Problem distinguishing empty REQUEST_URI with Apac

2019-09-17 16:23发布

问题:

I am running Apache witha redirect rule like this:

RewriteCond %{HTTP_HOST} ^1st-domain\.com
RewriteRule ^(.*)$ http://2nd-domain.com$1 [R=permanent,L]

This successfully redirects http://1st-domain.com to http://2nd-domain.com However, when the REQUEST_URI is empty, I want to redirect to a third domain.

RewriteCond %{HTTP_HOST} ^1st-domain\.com$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ http://3rd-domain.com$1 [R=permanent,L]

But this does not work and instead redirects to 2nd-domain.com

My rules are ordered like this:

RewriteCond %{HTTP_HOST} ^1st-domain\.com$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ http://3rd-domain.com$1 [R=permanent,L]

RewriteCond %{HTTP_HOST} ^1st-domain\.com
RewriteRule ^(.*)$ http://2nd-domain.com$1 [R=permanent,L]

Any suggestions? Thank you in advance.