Bulk Overwrite .htaccess file in all user accounts?

Sujoy Dhar

Well-Known Member
Jul 24, 2016
76
12
58
India
cPanel Access Level
Root Administrator
Twitter
Hi ,

I have a got a nice idea about the .htaccess file optimization but I am unable to proceed.

I have one file .htaccess in my server's root location but I want to copy or replace to all the cpanel user's home location i.e home/user/.htaccess

If Any body have the solution I will be too happy to complete these task

.htaccess content for this thread reader also if anyone wants to suggest on this :
Code:
<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    <IfModule mod_setenvif.c>
        # Netscape 4.x has some problems...
        BrowserMatch ^Mozilla/4 gzip-only-text/html

        # Netscape 4.06-4.08 have some more problems
        BrowserMatch ^Mozilla/4\.0[678] no-gzip

        # MSIE masquerades as Netscape, but it is fine
        # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

        # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
        # the above regex won't work. You can use the following
        # workaround to get the desired effect:
        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

        # Don't compress images
        SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    </IfModule>

    <IfModule mod_headers.c>
        # Make sure proxies don't deliver the wrong content
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
</IfModule>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
# BEGIN Expire headers
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 5 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
  ExpiresByType text/html "access plus 600 seconds"
  ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "public"
  </filesMatch>
  <filesMatch "\.(css)$">
    Header set Cache-Control "public"
  </filesMatch>
  <filesMatch "\.(js)$">
    Header set Cache-Control "private"
  </filesMatch>
  <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "private, must-revalidate"
  </filesMatch>
</ifModule>
# END Cache-Control Headers
# END Expire headers
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</Files>
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
ServerSignature Off
Options -Indexes
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,256
463
Hello,

Replacing the existing .htaccess files is not recommended. These files may already include entries related to features offered in cPanel & WHM (e.g. MultiPHP, Redirects, Optimize Website). This is generally something you'd want to handle on a per account basis.

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,256
463
Hello,

That level of modification would involve developing a custom bash script that searches for the .htaccess files and appending those files with a specific entry. I recommend reaching out to a qualified system administrator for help with this, as it's outside the scope of support we can offer:

System Administration Services | cPanel Forums

Thank you.
 

linux4me2

Well-Known Member
Aug 21, 2015
259
80
78
USA
cPanel Access Level
Root Administrator
It looks like at least some of what he's wanting to include in his .htaccess files could go in Home -> Service Configuration -> Apache Configuration -> Include Editor -> Previrtual Host Include -> All Versions. Would that work?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,256
463