The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

.htaccess Optimization and Optimize Website

Discussion in 'General Discussion' started by sparek-3, Jul 31, 2017.

  1. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,436
    Likes Received:
    31
    Trophy Points:
    178
    cPanel Access Level:
    Root Administrator
    Regarding the new .htaccess Optimization feature, if this is set to DocumentRoot doesn't this interfere with the Optimize Website feature in users cPanels?

    The Optimize Website (mod_deflate) adds a .htaccess file into the user's home directory. If AllowOverride is only permitted into individual DocumentRoots, then .htaccess file in the user's home directory will never be read, correct?

    Of course, if you use the recommended setting of per home directory, this is not an issue. And that may be the best solution here, just note that if you use per DocumentRoot AllowOverride then you won't be able to use The Optimize Website feature in end-user's cPanels. Otherwise, you would need to revamp the Optimize Website to be enabled per VirtualHost or a flag would have to be set so that subsequent VirtualHosts created under the end-user's account get the appropriate mod_deflate directives set in their .htaccess file.


    Would a better solution be to avoid .htaccess files completely? I believe this is what nginx does. Per VirtualHosts directives could be added to /etc/apache2/conf.d/userdata/(std|ssl)/2_4/<user>/<virtualhost> directory structure. The nginx argument is that each web-server request generates more file-system hits as it has to look for .htaccess files every where. I don't know how much of a performance hit this really is, but it makes sense that it would at least take some performance hit.
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    That's correct, if you set "Optimize .htaccess (AllowOverride)" to "Search Document Root and Below" in "WHM >> Apache Configuration >> Global Configuration", then the entries added to the "/home/$user/.htaccess" file when enabling the "Optimize Website" feature in cPanel are not detected. It also will prevent PHP inheritance from working, leading to potential issues with MultiPHP functionality. Setting the option to "Search Document Root and Below" is not recommended.

    That said, if you decided to configure the option to "Search Document Root and Below", then yes, enabling the mod_deflate entries directly in the virtual host is a suitable workaround:

    Modify Apache Virtual Hosts with Include Files - EasyApache 4 - cPanel Documentation

    I recommend opening a feature request if you'd like to see the default behavior switched from the .htaccess inclusion to a virtual host inclusion when using the "Optimize Website" option.

    Thank you.
     
  3. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,436
    Likes Received:
    31
    Trophy Points:
    178
    cPanel Access Level:
    Root Administrator
    Well, the rant about Would a better solution be to avoid .htaccess files completely was actually about doing away with the .htaccess behavior altogether - a la nginx.

    But yea, the Optimize Website probably needs to be moved into the user's Apache userdata directory structure.
     
Loading...

Share This Page