0

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.

1 Answer 1

1

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>
2
  • 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 Z
    Jun 29, 2009 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. Jun 29, 2009 at 18:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .