0

I'm trying to achieve this with mod rewrite:

If a user visits mysite.com/app/[somepage].php, they will see mysite.php/[somepage].php If a user visits mysite.com/[somepage].php, they will be rewritten to mysite.com/test.php

The value in square brackets are arbitrary.

This is what I have now:

RewriteRule ^app/(.+) $1 [NC,L]
RewriteRule ^(.+) test.php [NC,L]

However, both mysite.com/app/index.php and mysite.com/index.php will rewrite to mysite.com/test.php. It is as if the last rule is always processed. What is the correct way to achieve this?

Any help would be appreciated.

l3utterfly
  • 2,106
  • 4
  • 32
  • 58
  • Either use `[END]` with Apache 2.4 or mask the second rule with a `RewriteCond` for the `REDIRECT_STATUS`. – mario Aug 25 '14 at 03:55
  • Can you elaborate a bit more? I thought the L flag means the rewrite would stop processsing? – l3utterfly Aug 25 '14 at 03:58
  • 2
    See [Mod\_Rewrite unexpected behavior L flag](http://stackoverflow.com/a/12106419) and [How to block multiple mod\_rewrite passes (or infinite loops) in a .htaccess context](http://stackoverflow.com/q/7798099) – mario Aug 25 '14 at 04:01
  • RewriteCond %{ENV:REDIRECT_STATUS} 200 RewriteRule ^ - [L] worked. Thanks for the links. – l3utterfly Aug 25 '14 at 04:25
  • Or match `%{THE_REQUEST}` instead. – Sumurai8 Aug 25 '14 at 06:12

0 Answers0