Forum Moderators: phranque

Message Too Old, No Replies

htaccess folder rewrite

         

wallis2xk

11:42 am on Apr 13, 2008 (gmt 0)

10+ Year Member



Hi,

I'm trying to create a rewrite so any subfolders with go to index.php passing the folder names as variables behind the scenes. Something like this (but not as this isn't right)

RewriteRule http://example.com/([^/]+)/([^/]+)/([^/]+) http://example.com/index.php?s1=$1&s2=$2&s3=$3 [R]

Thanks

[edited by: jdMorgan at 12:51 pm (utc) on April 13, 2008]
[edit reason] example.com [/edit]

jdMorgan

12:51 pm on Apr 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Very close, though...

RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ /index.php?s1=$1&s2=$2&s3=$3 [L]

RewriteRule "sees" only the local URL-path for matching against your pattern; The path to the directory where the RewriteRule is running is stripped. So it does not "see" the domain name or anything in the directory path above "here" (note the leading slash is missing, because this code is intended to run in example.com/.htaccess)

Note also that RewriteRule cannot "see" the query string or anything else, only the local URL-path. If you need to test or back-reference query strings or the domain name, then you must use a RewriteCond along with the appropriate variable to do so.

If you don't have any other working mod_rewrite [httpd.apache.org] rules, you'll need to set up and enable mod_rewrite using either both of the following directives, or only the second one, before you can use RewriteRules -- Only testing can tell you if the first line is needed (or allowed):


Options +FollowSymLinks
RewriteEngine on

Jim

[edited by: jdMorgan at 12:54 pm (utc) on April 13, 2008]

wallis2xk

8:53 pm on Apr 13, 2008 (gmt 0)

10+ Year Member



thanks for the thorough reply, very helpful.