-
Directories that don't actually exist
I'm wondering how do you use PHP to make it look like there are directories that don't even exist.
I can't point to specific websites but I've worked on existing code (didn't have a chance to look at the code that did this function) where there are pages that look like www.mydomain.com/products/inside/Model# but only the products directory existed. There was not inside directory.
How do you do this? Does it require special configuration via apache or can it be done in only php?
-
Re: Directories that don't actually exist
This is acheieved in the server configuration . If you are using Apache you can use the URL Rewriter to morph the URLS.
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
This will work in .htaccess files provided your host has enabled the feature.
-
Re: Directories that don't actually exist
Thanks, I'll have to look further into that (though I could have sworn I didn't see any .htaccess files =/)
-
Re: Directories that don't actually exist
It can also be put in the main server configuration file httpd.conf.
-
Re: Directories that don't actually exist
Thanks.
I've been reading through the guide but am not really understanding how to adopt this for my situation.
Like, say I have a url that looks like this: www.binaryidiot.com/?area=software&product=perspective. How can I make it so the area and product get variables are still get correctly but the URL is shown as www.binaryidiot.com/software/perspective?
-
Re: Directories that don't actually exist
Anyone have any examples for the types of URLs I'm looking to create?
-
Re: Directories that don't actually exist
-
Re: Directories that don't actually exist
I thouhgt I had replied to this. Obviously not :ehh: In your .htaccess file or directory container inside the httpd.conf file you could have the following:
Code:
RewriteEngine on
RewriteRule ^/products/inside/Model_([0-9]+)/ /products/inside/model.php?model=$1
You may also want to set the ReqriteBase to the directory you are working with.
-
Re: Directories that don't actually exist
Quote:
Originally Posted by penagate
Thanks. It helped my understand but I am still having issues (do'h!).
I wanted to just test this with my current website which has URLs formatted like this:
Code:
http://www.binaryidiot.com/index.php?area=news&id=68
So my goal was to make them look like this:
Code:
http://www.binaryidiot.com/article/68/
So I basically copied and pasted the code from the website and just replaced a few parts with my website's information. Simple enough, right?
Code:
RewriteRule ^article/(.*)/$ index.php?area=news&id=$1
Doesn't work.
Quote:
Originally Posted by visualAd
I thouhgt I had replied to this
Oh you did. I'm just dumb sometimes (:()
After seeing visualAd's code I tried this:
Code:
RewriteEngine On
RewriteRule ^article/(.*)/$ index.php?area=news&id=$1
Still no go.
I then tried to modify visualAd's code because it had more slashes and ended up with something like this:
Code:
RewriteEngine on
RewriteBase /
RewriteRule ^/article/(.*)/ /index.php?area=news&id=$1
Still no go. I tested it on my current webserver as well as an internal apache server I have setup. Both looks like they're setup correctly. All of this is going into a .htaccess file as well in the same directory as index.php (I noticed in 1 of the articles it said to put it in the directory before the htdocs and I tried that as well with no luck).
So... what am I doing that's so wrong?
-
Re: Directories that don't actually exist
Have you ensured that mod rewrite has been orverriden in the httpd.conf file?
-
Re: Directories that don't actually exist
Quote:
Originally Posted by visualAd
Have you ensured that mod rewrite has been orverriden in the httpd.conf file?
I've searched all over the place. It looks like it's enabled on both my local server and my remote server but I still can't get anything working.
What do you mean by has it been overridden? I couldn't find anything on override mod rewrite.
-
Re: Directories that don't actually exist
In the main server configuration file for thee document root directory container, you need to have an AllowOverride driective. This allows directives to be overriden in the .htaccess files.
Code:
DocumentRoot /var/www
<Directory /var/www>
AllowOverride Indexes FileInfo
</Directory>
FileInfo includes the mod_rewrite directives.
-
Re: Directories that don't actually exist
visualAd please explain more is the phrase FileInfo supposed to be replaced with the filename?
-
Re: Directories that don't actually exist
No, you put this in the httpd.conf file for the directory that you want to allow .htaccess files to be able to use mod_rewrite in.
-
Re: Directories that don't actually exist
after doin all thats been said, i still get the object not found error.
pls help
-
Re: Directories that don't actually exist
What does your httpd.conf file and .htaccess file look like? - could you upload them?
-
1 Attachment(s)
Re: Directories that don't actually exist
I think I offically give up, lol. Still can't get anything to work. I thought it would be a simple .htaccess file or something but it doesn't work on my local server or remote server. Bah!
Here is my .htaccess:
PHP Code:
RewriteEngine on
RewriteBase /v4/
RewriteRule ^/v4/Article/(.*)/ /index.php?area=news&id=$1
I am putting that in the same directory as my index.php file (which resides in localhost/v4/). I tried changing it around like I mentioned before.
Attached is my httpd.conf file but I only changed the 1 thing you said (everything else is default). Though I saw you mention that the httpd.conf should go in the directory that you want the morph the DLLs. I thought it was supposed to go into only the conf directory.
-
Re: Directories that don't actually exist
Are you using user_dir directories i.e:
http://localhost/~username/v4/Article/5/
As fielinfo is only enabled for these.
Also, you need not use rewritebase in a .htaccess, as it is always relative to the directory which the .htaccess file is in:
Code:
RewriteEngine on
RewriteRule ^v4/Article/(.*)/ index.php?area=news&id=$1
Notice also how I've removed the forward slashes at the front to make it relative.
-
Re: Directories that don't actually exist
Quote:
Originally Posted by visualAd
I am not using user_dir directories. It's just http://localhost/v4/Article/5. My remote server has this enabled though so maybe I'll try that again.
Is there anyway to make it work without user_dir?
-
Re: Directories that don't actually exist
Quote:
Originally Posted by kasracer
I am not using user_dir directories. It's just
http://localhost/v4/Article/5. My remote server has this enabled though so maybe I'll try that again.
Is there anyway to make it work without user_dir?
You need also to enable FileInfo in the document root directory container too. URL rewriting is only cconerned with the URL, the location of the file on the server is irrelevant.
At present your entire document root directory container is commented out. Therefore, Apache will ignore it:
Code:
#<Directory "E:/apache/htdocs"> <---- a # at the beginning of a line makes it a comment.
#</Directory>
-
Re: Directories that don't actually exist
Thanks for all your help visualAd. I think I may agree with apache's docs about mod_rewrite
Quote:
With mod_rewrite you either shoot yourself in the foot the first time and never use it again or love it for the rest of your life because of its power. This paper tries to give you a few initial success events to avoid the first case by presenting already invented solutions to you.
I don't know why I still can't get it to work, lol. Honestly, I wanted a solution that I could just include in my .htaccess or something that way I could easily drop my website onto another server because I will most likely be changing servers sometime this year and possibly again next year. If I have to attempt to configure apache everytime (something I don't even have access to via my shared hosting right now), this solution probably won't work the way I want. I was hoping for something that would either turn a neat looking URL into something my PHP scripts could use like normal or maybe a way to use a php file to process all my URLs (like no matter where you go on my site, the URL is sent to 1 PHP script to determine where to put you).
Thanks again though. I'll keep trying for a little while longer heh
-
Re: Directories that don't actually exist
Did you make the changes I suggested above? It will work if you make them.
-
Re: Directories that don't actually exist
Quote:
Originally Posted by visualAd
Did you make the changes I suggested above? It will work if you make them.
Yeah it still didn't work. The odd thing is, Apache's service died about an hour or so after making the changes and I couldn't restart it. Attempting to restart the computer also did nothing so I had to unisntall it; lol. I'll reinstall and try again later. I also will e-mail my host to see if my remote server supports this.
-
Re: Directories that don't actually exist
Well I had cause to try this out myself today and I am happy to announce the RewriteRule works fine.
:)
-
Re: Directories that don't actually exist
I have never had any problems too. When you reinstall, upload your httpd.conf again. I am quite sure you have a missconfiguration.
-
Re: Directories that don't actually exist
Quote:
Originally Posted by v!sualAd
Code:
DocumentRoot /var/www
<Directory /var/www>
AllowOverride Indexes FileInfo
</Directory>
i finally got it to work!!!
i got it to work about 3 days ago but i couldn't get to forum then
but i used All instead of Indexes FileInfo
thanks visual