HTAccess Question

#1
[eluser]benjamin[/eluser]
Hi all,

I created virtual subdomains using .htaccess. If the user visits subdomain.example.com, then he will be re-directed to www.example.com/index.php/foo/bar:

Code:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/index.php/foo/bar/%1 [P,L]

All good so far.

However if users already specified a controller, then I want the url to be re-written to include this controller. E.g.
subdomain.example.com/index.php/lolcats ==> example.com/index.php/lolcats
I edit the .htaccess to include this code (which works in itself):
Code:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com/index\.php/([.*]) [NC]
RewriteRule ^index.php/(.*)$ http://www.example.com/index.php/%1 [P,L]

However I'm running into problems when I combine the two rewrite rules. Then, only the former works, despite me using L to ignore any subsequent rules.

My .htaccess:

Code:
RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com/index\.php/([.*]) [NC]
RewriteRule ^index.php/(.*)$ http://www.example.com/index.php/%1 [P,L]

RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/index.php/foo/bar/%1 [P,L]

Any help would be greatly appreciated.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.