0

RewriteBase is set in httpd.conf for an alias:

Alias /test /home/user/test
<Directory "/home/user/test">
    AllowOverride All
    Allow from All

    RewriteEngine On
    RewriteBase /test
    RewriteRule ^foo$ foo.html [QSA,L]
</Directory>

This works fine: http://example.com/test/foo is foo.html.

Now, I'd like to move the RewriteRule to .htaccess, because that's where it makes more sense. It's a configuration for the test project after all. However, if I do that, then RewriteBase is not interpreted any longer, and loading http://example.com/test/foo fails.

Is there any way to set RewriteBase in httpd.conf plus RewriteRule in .htaccess?

feklee
  • 505
  • 3
  • 18
  • I don't see the point of moving it to .htaccess specifically. The reasons to use .htaccess are if a) you don't have access to httpd.conf, or b) you expect to change the config often and don't want to restart httpd. Otherwise, keeping it in httpd.conf (or its `#include` files) makes a lot more sense. You should know that .htaccess is re-read on *every* http request for that location, which increases the overhead - not by much, but depending on your usage stats it may end up being significant. – Jenny D Mar 10 '14 at 10:25
  • @JennyD It's a PHP app (Symfony 1.4) that is installed on various servers, under different aliases, but with the same rewrite rules. – feklee Mar 10 '14 at 10:27
  • Darn. I was so sure I had the two only possible cases where .htaccess is the right solution, and then you just had to overthrow my world view by being reasonable and right about a third one! – Jenny D Mar 10 '14 at 10:49
  • @JennyD You made me think about an alternative solution: I could put the common rewrite rules into an [include file](http://httpd.apache.org/docs/2.2/mod/core.html#include), which is kept with the project (in GIT). Then only we should not forget to reload server config whenever the include file changes. – feklee Mar 10 '14 at 10:58
  • 1
    That is the way I'd do it, provided changing the file isn't something that happens too often. – Jenny D Mar 10 '14 at 10:59
  • I don't see why this topic was marked as duplicate. I have the same conditions and requirements. What's the answer to the question? Why is the `RewriteBase` from the `httpd.conf` ignored? – HenningCash Jun 19 '14 at 08:52

0 Answers0