.htaccess RewriteRule not working with root ‘/’

.htaccessapache-2.2mod-rewrite

I'm struggling to get this .htaccess rewrite working correctly:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) old/$1 [L]
</IfModule>

I have a directory structure like this:

/subdir/
    .htaccess
    /old/
    /wp/

I want all requests to http://myserver.com/subdir/ to be rewritten to http://myserver.com/subdir/old/, expect those pointing to the /wp/ directory. The .htaccess above works fine when a file or directory is specified (e.g. http://myserver.com/subdir/index.html) but when only the /subdir/ is present it gives a 403 response (I'm assuming the 403 is because I have directory listing disabled).

Many thanks to anyone who can point me in the right direction with this.

Best Answer

This seemed to do the trick, even if I don't know why exactly!

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdir/
RewriteCond $1 !^old/(.*)
RewriteCond $1 !^wp/(.*)
RewriteRule ^(.*)$ old/$1 [L]
</IfModule>
Related Topic