Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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]

I have a directory structure like this:


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.

share|improve this question

1 Answer 1

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]
share|improve this answer
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 Z 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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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