Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite - Htaccess inheritance

I've read the doc but still don't get htaccess inheritance to work for me

         

pixeline

11:26 am on Jan 23, 2008 (gmt 0)

10+ Year Member



Hello,

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)

vincevincevince

12:06 pm on Jan 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



in "^projects" you start with ^. ^ refers to the beginning of the string - the very beginning / root of the path. Try dropping the ^ or adding in /domain.com/v2/ between ^ and projects

phranque

12:09 pm on Jan 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], Alexandre!

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.

pixeline

12:21 pm on Jan 23, 2008 (gmt 0)

10+ Year Member



hi Vince & Phranque,
Nice forum, i'll stick to it!


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?

pixeline

1:38 pm on Jan 23, 2008 (gmt 0)

10+ Year Member



so i tried applying your comments but so far no luck. Problem is, where there is a date, it could also be a string

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]


Now, i realize my first line doesn't work properly, if i try
"http://localhost/domain.com/v2/projects/time/2006/touch/"
it redirects to the url, with the local path appended!

i guess the mistake is in the $1/$2/$3/$4 . Digging some more...