Note that there are some explanatory texts on larger screens.

plurals
  1. POApplying mod_rewrite rules AFTER DirectoryIndex is applied
    text
    copied!<p>My hosting company recently upgraded me from Apache 1 to Apache 2, and I've started seeing some quite different behaviour with my mod_rewrite stuff.</p> <p>Here's my .htaccess file:</p> <pre><code>DirectoryIndex blog.html # Various rewrite rules. &lt;IfModule mod_rewrite.c&gt; RewriteEngine on # Rewrite current-style URLs of the form 'showpage.php?url=x'. RewriteRule ^(.*\.html)$ showpage.php?url=$1 [L,QSA] &lt;/IfModule&gt; </code></pre> <p>Now, previously with Apache 1, if you went to <a href="http://mysite.com/" rel="noreferrer">http://mysite.com/</a> then the DirectoryIndex would first take effect (<a href="http://mysite.com/blog.html" rel="noreferrer">http://mysite.com/blog.html</a>) and then the RewriteRule would turn that into <a href="http://mysite.com/showpage.php?url=/blog.html" rel="noreferrer">http://mysite.com/showpage.php?url=/blog.html</a></p> <p>Now with Apache 2, if you go to <a href="http://mysite.com/blog.html" rel="noreferrer">http://mysite.com/blog.html</a> it gets rewritten as expected, but if you go to <a href="http://mysite.com/" rel="noreferrer">http://mysite.com/</a> it serves you the vanilla blog.html file, without rewriting it to showpage.php. So the RewriteRule is being applied <em>before</em> the DirectoryIndex kicks in.</p> <p>Besides adding an extra rule explicitly to catch the root page (which will be tedious since I'd have to take account of all subdirectories which also have a DirectoryIndex) does anybody know a way to make Apache 2 apply the RewriteRule <em>after</em> applying the DirectoryIndex?</p>
 

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