Forum Moderators: phranque
There is one thing i still don't get about mod_rewrite:
From the apache doc, i understood that an .htaccess in the root folder will affect all its subfolder, unless overwritten by subfolder-specific .htaccess files.
Is this correct or not? Does it need a special setting so that it works this way?
For now, here is my htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^projects/([A-Za-z]+)/([A-Za-z]+)/([A-Za-z]+)/([A-Za-z]+)$ projects/$1/$2/$3/$4/ [R]
RewriteRule ^projects/([A-Za-z]+)/([A-Za-z]+)/([A-Za-z]+)/([A-Za-z]+)/$ metalab2.php?section=$1&sortBy=$2&dsAnchor=$3&item=$4
but if i try [localhost...]
it says "The requested URL /domain.com/v2/projects/time/2006/touch was not found on this server." which is true of course, only the "projects/" folder physically sits on the server. the rest are query vars.
Thanks for your help,
Alexandre
PS: i'm testing on a wampserver local instalation. (PHP5,mysql5)
not sure what's up with your path there and how it relates to your server root, but i would look into that.
what is "v2" and why is "domain.com" in there if your domain is "localhost" in this case?
also, your regexp should be changed to recognize the year string in the second field after "/projects/" and is looking for a 4th field that doesn't exist.
maybe that should be more like:
RewriteRule ^projects/([A-Za-z]+)/([0-9]{4})/([A-Za-z]+)$ projects/$1/$2/$3/ [R]
(and presumably the equivalent fixes in the local rewrite that follows)
finally the "R" code defaults to a 302 response, so make sure you want that to be a temporary redirect and not a permanent redirect.
not sure what's up with your path there and how it relates to your server root, but i would look into that.
what is "v2" and why is "domain.com" in there if your domain is "localhost" in this case?
Sorry i was unclear:
it's my local testing server (a wampserver installation).
since i have many websites, i create one folder with the domain name.
v2/ is the redesign of that domain name :)
so in fact the .htaccess file sits in the v2 folder.
i'll see if i can fix my regexp and get back to you, thanks!
In the meanwhile, can you tell me what i should put so that it redirects to the domain root instead of throwing 404?
is it correct like this?
RewriteRule ^/([A-Za-z0-9]+)/([A-Za-z0-9]+)/([A-Za-z0-9]+)/([A-Za-z0-9]+)$ /$1/$2/$3/$4/ [R]
RewriteRule ^/([A-Za-z0-9]+)/([A-Za-z0-9]+)/([A-Za-z0-9]+)/([A-Za-z0-9]+)/$ metalab2.php?section=$1&sortBy=$2&dsAnchor=$3&item=$4 update:
just found the kwirk, here is the updated rule:
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ $1/$2/$3/$4/ [R]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/$ metalab2.php?section=$1&sortBy=$2&dsAnchor=$3&item=$4 [L] i guess the mistake is in the $1/$2/$3/$4 . Digging some more...