I'm trying to have this URL rewritten as follow:
fr.example.com/tag/movies
»example.com/catch.php?country=fr&tag=movies
example.com/tag/movies
»example.com/catch.php?tag=movies
fr.example.com
»domain.com/catch.php?country=fr
for these, I have the following mod_rewrite rules in a .htaccess file
subdomain + tag
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com [NC] RewriteRule ^tag/([^/]+) catch.php?country=%1&tag=$1 [L,NS]
tag
RewriteRule ^tag/([^/]+) catch.php?tag=$1 [L,NS]
subdomain
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com [NC] RewriteRule ^(.*)$ catch.php?country=%1 [L,NS]
in this order exactly.
Now, the L
after the first RewriteRule
should end processing and redirect it to the subdomain+tag URL, but it doesn't. For example, fr.example.com/tag/movies
is sent to catch.php?country=fr
, which is the last condition in the .htaccess
file.
Shouldn't it stop after the first L
is found?
ANSWER
Well, it turns out that the [L]
flag works differently depending on the context (.htaccess
/<Directory>
different from httpd.conf
) as you can see here.
So, to make it work just place the rules inside the <VirtualHost>
(NOT <Directory>
) and add a /
to every URI (/catch.php
, /tag
, ...). That's it.