Note that there are some explanatory texts on larger screens.

plurals
  1. PO.htaccess RewriteRules matched, but rewritten wrongly
    text
    copied!<p>On my server I have a .htaccess file with the following contents:</p> <pre><code>RewriteCond %{HTTP_HOST} ^myhost.local$ RewriteRule ^default/.*$ /index.php?id=12345 [L] RewriteCond %{HTTP_HOST} ^myhost.local$ RewriteCond %{REQUEST_URI} ^/?$ RewriteRule ^(.*)$ http://myhost.local/default/home [R=302,NC] </code></pre> <p>The phenomenon is that when requesting <a href="http://myhost.local/" rel="nofollow">http://myhost.local/</a>, instead of being 302 redirected to <a href="http://myhost.local/default/home" rel="nofollow">http://myhost.local/default/home</a> as expected, I am being 301 (!) redirected back to <a href="http://myhost.local/" rel="nofollow">http://myhost.local/</a>, resulting in an infinite loop.</p> <p>Another strange thing is that <code>^/$</code> never seems to match my URL even though it should, so I have to use <code>^/?</code> with a question mark for some reason. Whenever there's no match, no rewriting happens and therefore there are no infinite loops, so this is further evidence that my <code>RewriteRule</code> for <code>^(.*)$</code> is indeed picked up on if the Condition is satisfied, only what I want to redirect to and with what code is completely ignored.</p> <p>For the record, I have also had the rules in this format:</p> <pre><code>RewriteCond %{HTTP_HOST} ^myhost.local$ RewriteRule ^default/.*$ /index.php?id=12345 [L] RewriteCond %{HTTP_HOST} ^myhost.local$ RewriteRule ^/?$ http://myhost.local/default/home [R=302,NC] </code></pre> <p>Which resulted in exactly the same thing as the first example.</p> <p>What is causing the redirection to happen, but not to the URL I actually gave?</p> <p>Things to note:</p> <ul> <li>There are other entries in this .htaccess file</li> <li>This .htaccess file is within DOCUMENT_ROOT</li> <li>The default VirtualHost has <code>RewriteOptions inherit</code> set</li> </ul>
 

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