Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Bulk Overwrite .htaccess file in all user accounts?

Discussion in 'General Discussion' started by Sujoy Dhar, Mar 31, 2018.

  1. Sujoy Dhar

    Sujoy Dhar Active Member

    Joined:
    Jul 24, 2016
    Messages:
    34
    Likes Received:
    5
    Trophy Points:
    8
    Location:
    India
    cPanel Access Level:
    Root Administrator
    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
    
    
     
    #1 Sujoy Dhar, Mar 31, 2018
    Last edited by a moderator: Mar 31, 2018
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,806
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Sujoy Dhar

    Sujoy Dhar Active Member

    Joined:
    Jul 24, 2016
    Messages:
    34
    Likes Received:
    5
    Trophy Points:
    8
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Dear,

    I am respecting the codes inside the cpanel root and adding some other codes too for optimization thats why I need the command to run in ssh , if you could help me I will be highly appreciated !
     
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,806
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. linux4me2

    linux4me2 Well-Known Member

    Joined:
    Aug 21, 2015
    Messages:
    201
    Likes Received:
    47
    Trophy Points:
    28
    Location:
    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?
     
  6. Sujoy Dhar

    Sujoy Dhar Active Member

    Joined:
    Jul 24, 2016
    Messages:
    34
    Likes Received:
    5
    Trophy Points:
    8
    Location:
    India
    cPanel Access Level:
    Root Administrator
  7. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,806
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice