Reputation: 11358
If you have access to the main server configuration file (usually called
httpd.conf
), you should add the logic from the.htaccess
file in, for example, a<Directory>
section in the main configuration file. This is usually the recommended way, as using.htaccess
files slows down Apache! (Source)
I think it essentially means, if possible, I should Include httpd.conf
along with the AllowOverride None
directive in /etc/apache2/apache2.conf
.
But semantics (or whatever) aside, why can't I simply include .htaccess
itself? For my convenience I am doing it like this...
File: /etc/apache2/apache2.conf
#
# [... ORIGINAL CONTENTS OF APACHE2.CONF ...]
#
<Directory /var/www/example.com/public>
DirectoryIndex index.php index.html
AllowOverride None
Include /var/www/example.com/public/.htaccess
</Directory>
With the .htaccess
file included in apache2.conf
, and the AllowOverride None
directive in place, I can simply add all my site's rewrite rules in /var/www/example.com/public/.htaccess
.
If need to use another .htaccess file for another sub-directory, I simply add another Include
for the new .htaccess
file in apache2.conf
just the way I am doing it now.
My question is, is this just as performant as using httpd.conf
? (I believe I was told otherwise here, which is why I am asking.) If not, why not?
Reason why I prefer using .htaccess: My server runs WordPress, and some WordPress plugins I use (SEO, caching, etc.) add rewrite rules in .htaccess files. By using .htaccess I don't have to do this manually myself, and can simply let the plugins do their job.
Upvotes: 2
Views: 790
Reputation: 17886
Yes, it's the same runtime performance as putting it directly in httpd.conf. The operative part is that it's parsed at startup, not while mapping a request to the filesystem and checking for htaccess and interpreting it each time.
Upvotes: 2