Forum Moderators: phranque
at example.com/index.php I load a random image, that image will link to something like:
example.com/pictures/cars/1345
The path /pictures/cars/1345 does not exist, all I want to do is pull the 1345 away, and use that to lookup a record in a database. There never will be a url in the form of index.php?id=1345, as I am starting fresh with this site. I am able to successfully use php to grap the 1345 our of the uri.
I tend to be able to get this to work with a rewrite rule
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
The problems I am running into are with how the rest of the site needs to work. So if someone goes to example.com/dasda/dsad/21321 since that path does not exist, it should 404 on them. I only want this feature working for urls that are /pictures/cars/some_number
If that real path did in fact exist, it should load the page.
I have /faq/ as a real directory, and /faq/dasd/das/dadas is obviously not, though both of those seem to get intercepted by the rewrite rule, rather than getting a 404 served up.
I think that is it, much appreciated.
Simplify:
Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^pictures/cars/[0-9]+$ /index.php [L]
Be aware that in order for this to work, you must be using AcceptPathInfo. Therefore, this code (and your site) will only work on Apache 2.0 and later. Apache 1.3.x and earlier does not support the AcceptPathInfo directive. Apache 1.3 and earlier would have to use the "GET" method -- That is, change the script to use GET parameters, and change the rule to something like "RewriteRule ^pictures/cars/([0-9]+)$ /index.php?pic_num=$1 [L]"
Jim
I have read as much of the docs as I can grok, I have specific uses that seem pretty common, but I can not wrap my head around, so I came here.
Server version: Apache/1.3.41 (Darwin)
I am working as always, on a test site, which is more or less a staging ground where I will move these edits to when I test them to make sure they work.
I just put in your sample, and even though I am on 1.3, it seems to work. I enabled rewrite logging, and it appears to be doing correct.
http://example.com/pictures/cars/21312
in php, I am able to get back
Array ( [0] => [1] => pictures [2] => cars [3] => 21312 )
Any other messing with the URL gives me a 404.
I tried your 1.3x specific one, it works as well.
All I am doing is using php to take the current url and split it apart on '/' and give me the chunk I want. Thanks for your help, is there any reason you think I am still doing something wrong?