2

Following Exception doesn't work. http://www.domain.com with and without /test redirect to http://www.example.de/foo/, but the exception should not!

RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/test$
RewriteRule ^(.*)$ http://www.example.de/foo/ [R=302,L]

What's the reason?

10

It conflicts with the rule

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

at the end of the .htaccess file.

If I add an exception for index.php like

RewriteCond %{HTTP_HOST} ^www.domain.example$ [NC]
RewriteCond %{REQUEST_URI} !^/test$
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^(.*)$ http://www.example.org/foo/ [R=302,L]

then it works.

| improve this answer | |
1

I found this as a solution to my problem, but found that I needed to add another "root" request conditional driven rewrite rule to make my final solution work. Depending on the logic required, it may look as follows:

RewriteCond %{HTTP_HOST} ^www.domain.example$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /some-uri [L,R=302]

RewriteCond %{HTTP_HOST} ^www.domain.example$ [NC]
RewriteCond %{REQUEST_URI} !^/some-uri$
RewriteRule ^(.*)$ /some-uri [L,R=302]
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /some-uri [L,R=302]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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