0

Windows server, running Apache. In my Apache conf, I have AllowOverride None for the root of a site and then I have a subdirectory set to AllowOverride All:

<Directory />
    AllowOverride None
</Directory>
<Directory "/safe/">
    AllowOverride All
</Directory>

However, when I try to set up a rewrite rule in the subdirectory's .htaccess file, nothing happens, I just get a 404 page not found error. Example:

RewriteEngine On
RewriteRule (.*) /blah?test=$1 [R=302,NC,NE,L]

Rewriting URLs are working fine from the root via the Apache conf. I don't understand why the rule is ignored. I don't want to do the URL re-writing within the conf because for this case I may need to be changing the redirects constantly and don't want to reload the server every time a change is made. I also don't want to affect server performance by enabling .htaccess files site-wide, just in the subdirectory I need it.

1

1 Answer 1

1

Beware of Directory & Location tags in Apache configuration, they have really differents meaning. Directory works on filesystem & location on URIs.

If you're talking about an URL like this: http://example.com/safe/index.html you should do like this:

<Location /safe>
    AllowOverride All
</Location>
1
  • The AllowOverride directive is only permitted in <Directory> sections, not <Location> sections. AllowOverride applies to filesystem paths, not URLs.
    – DocRoot
    Aug 27, 2017 at 1:01

You must log in to answer this question.