Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem detecting empty REQUEST_URI with Apache mod_rewrite
    primarykey
    data
    text
    <p>I am running Apache witha redirect rule like this:</p> <pre><code>RewriteCond %{HTTP_HOST} ^1st-domain\.com RewriteRule ^(.*)$ http://2nd-domain.com$1 [R=permanent,L] </code></pre> <p>This successfully redirects <a href="http://1st-domain.com" rel="noreferrer">http://1st-domain.com</a> to <a href="http://2nd-domain.com" rel="noreferrer">http://2nd-domain.com</a> However, when the REQUEST_URI is empty, I want to redirect to a third domain.</p> <pre><code>RewriteCond %{HTTP_HOST} ^1st-domain\.com$ RewriteCond %{QUERY_STRING} ^$ RewriteRule ^(.*)$ http://3rd-domain.com$1 [R=permanent,L] </code></pre> <p>But this does not work and instead redirects to 2nd-domain.com</p> <p>My rules are ordered like this:</p> <pre><code>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] </code></pre> <p>Any suggestions? Thank you in advance.</p> <p><strong>UPDATE</strong></p> <ol> <li>Empty REQUEST_URI: http:/1st-domain.com</li> <li>Non-empty REQUEST_URI: <a href="http://1st-domain.com/something" rel="noreferrer">http://1st-domain.com/something</a></li> </ol> <p>The first rule should direct an empty request_uri to 3rd-domain.com, the second rule should direct the non-empty request_uri to 2nd-domain.com</p> <p><strong>USEFUL TIDBIT</strong> You can turn on mod_rewrite debug with this snippet:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteLog "/home/domain.com/logs/rewrite.log" RewriteLogLevel 3 &lt;/IfModule&gt; </code></pre> <p>Very useful debug option I hadn't known.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload