1

I understand that httpd.conf is no longer available in Apache at /etc/apache2. A fix is that I could create a httpd.conf file as detailed here and point my apache2.conf to it.

But browsing through the apache2.conf, I noticed this:

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

Does this mean that I can safely add my .htaccess configs to my .conf file at /etc/apache2/sites-enabled/mysite.com.conf ?

Adding server configs to .htaccess can slow things down, especially when you add a bunch of them as shown here, and I want to make sure I'm adding them in the most prudent location.

  • If Apache 2 is setup to use VirtualHosting then you put the .htacess file in the root directory of each host. There's no need to add any conf files... – eyoung100 Aug 27 '16 at 20:12
  • Yes, I understand this. But I also have read that having a bunch of configure in .htaccess can slow down page delivery time? So, my goal was to move these settings to a location where it would not have this effect - basically closer to the core of Apache. – Vaughn D. Taylor Aug 28 '16 at 15:20

2 Answers2

0

It depends on the directives being used in the .htaccess file.

You can't necessarily simply copy (or include) the same directives from .htaccess and use them unaltered in a server or virtualhost context, which is suggested here. .htaccess files work in a directory context, so you can potentially copy them verbatim into a corresponding <Directory> container inside the vHost or server config.

The notable directives here are mod_rewrite - which work differently in a server (or virtualhost) context vs .htaccess (or directory) context.

For example, if the .htaccess file is located at /var/www/user/public_html/.htaccess then you could use the following in the vHost container instead:

<Directory /var/www/user/public_html>
    # Disable .htaccess overrides
    AllowOverride None
# .htaccess directives go here...
# :

</Directory>

However, you may not want to do this. It might be preferable to modify the directives so they work in a virtualhost context instead. Unless you completely disable .htaccess overrides (as mentioned above with AllowOverride None and possibly AllowOverrideList) then any .htaccess file along the filesystem path will override the <Directory> container in the vHost.

Adding server configs to .htaccess can slow things down

Note that in order to get the (marginal) performance benefit, you need to completely disable .htaccess overrides in the server config (as mentioned above). Simply removing the .htaccess file(s) is not sufficient since the server will still search for them in every directory along the requested filesystem path.

MrWhite
  • 183
0

You should create a .conf file for your site in /etc/apache2/conf-available/ and put there all your server settings that you don't want in .htaccess. Then enable that config using a2enconf (which will create a symlink in /etc/apache2/sites-enabled.

See /usr/share/doc/apache2/README.Debian.gz for more about how the Apache configuration is handled in Debian and its derivatives like Ubuntu.