ibram
ibram

Reputation: 140

Dynamic RewriteRule in .htaccess

Is there a way to combine this:

RewriteCond %{THE_REQUEST} (user-x/project/www)
RewriteRule ^.*$ /user-x/project/www/index.php [NC,L]

RewriteCond %{THE_REQUEST} (user-y/project/www)
RewriteRule ^.*$ /user-y/project/www/index.php [NC,L]

RewriteCond %{THE_REQUEST} (user-z/project/www)
RewriteRule ^.*$ /user-z/project/www/index.php [NC,L]

To a "dynamic" rule which works for "n" users?

I had this in mind:

RewriteRule ^/([a-z]+)/project/www/index.php$ /$1/project/www/index.php [NC,L]

Unfortunately the first argument of RewriteRule doesn't include the whole path when matching with a regex.

Any ideas?

Edit: .htaccess file is located in the "www" directory.

Upvotes: 1

Views: 80

Answers (1)

Jon Lin
Jon Lin

Reputation: 143966

Not sure why you're trying to match against %{THE_REQUEST}, which is actually the request and not the URI. But you can combine like:

RewriteCond %{THE_REQUEST} (user-x|user-y|user-z)/project/www
RewriteRule ^ /%1/project/www/index.php [L]

But the %{THE_REQUEST} variable actually looks something like this:

GET /some/path/maybe/a/user-x/project/www/and/some/more/stuff HTTP/1.1

And the above condition would match the above request. Otherwise, you can be more specific about wat to match:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(user-x|user-y|user-z)/project/www/?($|\ )
RewriteRule ^ /%1/project/www/index.php [L]

Upvotes: 1

Related Questions