Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to have this URL rewritten as follow:

  • fr.domain.com/tag/movies » domain.com/catch.php?country=fr&tag=movies
  • domain.com/tag/movies » domain.com/catch.php?tag=movies
  • fr.domain.com » domain.com/catch.php?country=fr

for these, I have the following mod_rewrite rules on a .htaccess file

  • subdomain + tag

    RewriteCond %{HTTP_HOST} ^([^.]+).domain.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} ^([^.]+).domain.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.domain.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 found?

thanks in advance, cheers

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The L flag won't stop processing under all circumstances. I'd suggest checking out this thread on Stack Overflow, especially the link to the Apache Rewrite Guide, and also turning on the RewriteLog so that you can confirm how mod_rewrite is processing your rules.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.