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?

2 Answers 2

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.

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]
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .