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.

link|improve this question
feedback

1 Answer

up vote 1 down vote accepted

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>
link|improve this answer
1  
In your original .htaccess rules I think the RewriteCond %{REQUEST_FILENAME} !-d would fail for requests for /subdir/ itself. (Also, it's generally preferable to put these rules in a <Directory> section in the main server config rather than using a .htaccess file) – David Zaslavsky Jun 29 '09 at 14:16
Thanks David, that makes more sense now. Unfortunately this is a shared hosting environment so I don't have any access to the server, otherwise I wouldn't need to use mod_rewrite at all. – Rory Fitzpatrick Jun 29 '09 at 18:39
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.