I start Apache with a redirect rule as follows:
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 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 organized as follows:
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.
UPDATE
The first rule should direct empty request_uri to 3rd-domain.com, the second rule should direct non-empty request_uri to 2nd-domain.com
USEFUL INFORMATION You can enable mod_rewrite debugging using this snippet:
<IfModule mod_rewrite.c> RewriteLog "/home/domain.com/logs/rewrite.log" RewriteLogLevel 3 </IfModule>
A very useful debugging option that I did not know about.
source share