Using include files instead of htaccess

GoWilkes

Well-Known Member
Sep 26, 2006
495
12
168
cPanel Access Level
Root Administrator
I'm looking at the documentation, and have questions:


I have an extensive .htaccess file on one of my sites, and I'd like to move it here to improve load time and for security.

My first question is about SSL. In my .htaccess, I redirect non-SSL users to the SSL page. But since this has a different file for SSL vs non-SSL, does that mean that I STILL have to have an htaccess file for this?

Second question is about the Apache version. It wants you to explicitly define /2_4/, but what happens when there's an update to 2.5? Does the directory change automagically?

Third question is about compression. My regular htaccess is at /home/account/www/, but when I use "Optimize Website" in cPanel it puts the info in the htaccess at /home/account/. Can I combine them in the include file?

Similarly, can I just copy this information to /etc/apache2/conf.d/userdata/includename.conf and let it apply to ALL of my websites? I understand that I have to create the literal /userdata/ directory manually, but what should "includename" actually be?

Fourth question is about the htaccess data itself. Is this a direct copy-and-paste, or do I need to modify RewriteConds and RewriteRules?

The docs say to use /etc/apache2/conf.d/userdata/ssl/2_4/user/includename.conf, where /user/ would be the actual user's name and not the literal word "user". But what should "includename" actually be?

Fifth question... WHM plugs in 6 lines of RewriteCond for EVERY rule that I have, effectively making the file size much larger than it needs to be. Will they still be plugged in to the include file, or can I modify it with this line at the top and not worry about cPanel modifying it?

Code:
RewriteRule ^(\d+\..+\.cpaneldcv|[A-F\d]{32}\.txt(?:\ Comodo\ DCV)?|\.well-known/(pki-validation/([A-F\d]{32}\.txt(?:\ Comodo\ DCV)?|(?:\ Ballot169)?)|acme-challenge/[\w-]+|cpanel-dcv/[\w-]+)) - [L]
And final question, once I have everything set up for my site, how do I turn off .htaccess for that one site entirely so that Apache doesn't waste time looking for it?
 

cPanelChris

Moderator
Staff member
Feb 16, 2020
38
4
8
Houston, TX
cPanel Access Level
Root Administrator
Hello @GoWilkes ,

My first question is about SSL. In my .htaccess, I redirect non-SSL users to the SSL page. But since this has a different file for SSL vs non-SSL, does that mean that I STILL have to have an htaccess file for this?
You should be able to place the redirect in the non-SSL include. So a .htaccess file should not be required for this.

Second question is about the Apache version. It wants you to explicitly define /2_4/, but what happens when there's an update to 2.5? Does the directory change automagically?
I would not expect the directory to be updated automagically. I would recommend double-checking this if Apache is updated to 2.5.

Third question is about compression. My regular htaccess is at /home/account/www/, but when I use "Optimize Website" in cPanel it puts the info in the htaccess at /home/account/. Can I combine them in the include file?
mod_deflate directives can be used in the include file. Adding the mod_deflate directives in /etc/apache2/conf.d/userdata/ssl/2_4/user/includename.conf would be equivilent to adding them in /home/account/.htaccess. Adding them to /etc/apache2/conf.d/userdata/ssl/2_4/user/domain/includename.conf would be equivilent to adding them to /home/account/www/.htaccess.

Similarly, can I just copy this information to /etc/apache2/conf.d/userdata/includename.conf and let it apply to ALL of my websites? I understand that I have to create the literal /userdata/ directory manually, but what should "includename" actually be?
Correct. The include files in /etc/apache2/conf.d/userdata/ will apply to all sites, with and without SSL. includename can be anything you want. The only requirement is that the file name must end with ".conf". This is because the wildcard include statements specify "*.conf" files to be included. For example:

Include "/etc/apache2/conf.d/userdata/std/2_4/user/domain.tld/*.conf"

Fourth question is about the htaccess data itself. Is this a direct copy-and-paste, or do I need to modify RewriteConds and RewriteRules?
You should be able to copy them from the .htaccess file into the include file.

The docs say to use /etc/apache2/conf.d/userdata/ssl/2_4/user/includename.conf, where /user/ would be the actual user's name and not the literal word "user". But what should "includename" actually be?
Again, includename can be anything, so long as the file name ends with ".conf".

Fifth question... WHM plugs in 6 lines of RewriteCond for EVERY rule that I have, effectively making the file size much larger than it needs to be. Will they still be plugged in to the include file, or can I modify it with this line at the top and not worry about cPanel modifying it?
I don't believe cPanel will modify the include files.

And final question, once I have everything set up for my site, how do I turn off .htaccess for that one site entirely so that Apache doesn't waste time looking for it?
Per the Apache documentation, setting both AllowOverride and AllowOverrideList to None will prevent Apache from even attempting to read .htaccess files.
 

GoWilkes

Well-Known Member
Sep 26, 2006
495
12
168
cPanel Access Level
Root Administrator
Awesome information, thanks!

One last question, then, until I try it and mess something up...

Is there a speed advantage to having a single .conf as opposed to multiple? Meaning, could I have:

/etc/apache2/conf.d/userdata/ssl/2_4/user/rule_1.conf
/etc/apache2/conf.d/userdata/ssl/2_4/user/rule_2.conf
/etc/apache2/conf.d/userdata/ssl/2_4/user/rule_3.conf

and so on, making it easier to maintain and update as needed? Or should I really only have a single .conf with all of the rules, like I have with .htaccess?
 

cPanelChris

Moderator
Staff member
Feb 16, 2020
38
4
8
Houston, TX
cPanel Access Level
Root Administrator
Hello @GoWilkes ,

I believe the include files would only be read when the Apache configuration being parsed, as in when Apache is being started or it receives a SIGHUP signal. So I would not expect there to be a performance hit when loading a site due to this.