Jump to content

htaccess configuration


Recommended Posts

A little example allow you to configure your htaccess to increase the speed and security

 

Options -Indexes
Options +FollowSymlinks

#### Your config to change ###############
#AllowOverride All
 AcceptPathInfo on


##################################
# Security
##################################



<IfModule mod_headers.c>
# prevent mime based attacks
Header set X-Content-Type-Options "nosniff"

# XSS Protection
Header set X-XSS-Protection "1; mode=block"

#content policy
#Header set Content-Security-Policy "script-src 'self' https://www.mydomain.org"

#X Frame
Header always set X-FRAME-OPTIONS "DENY"
</IfModule>


#Header always append X-Frame-Options SAMEORIGIN
#CORS
# Always set these headers.
#Header always set Access-Control-Allow-Origin "*"
#Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
#Header always set Access-Control-Max-Age "1000"
#Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"

#### Your config to change URL rewriting ###############
#Uncomment and adapt
<IfModule mod_rewrite.c>
RewriteEngine On

## URL Canonicalization
#to change in function your website
    RewriteBase /shop/

    RewriteCond %{HTTP_HOST} !^mydomain.org$ [NC]
    RewriteRule ^(.*)$ https://www.mydomain.org/$1 [L,R=301]

#to change in function your website
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

#to change in function your website
    RewriteRule . /shop/index.php [L]


#Caching schema
<IfModule mod_headers.c>
  Header unset ETag
</IfModule>

#Caching schema

## EXPIRES CACHING ##
## https://gtmetrix.com/leverage-browser-caching.html ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType font/opentype "access plus 1 year"
ExpiresByType font/ttf "access plus 1 year"
ExpiresByType font/otf "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-otf "access plus 1 year"
</IfModule>

#apache 2.4
  <IfModule mod_version.c>
      <IfModule mod_filter.c>
        <IfVersion >= 2.4>
            FilterDeclare COMPRESS
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/html'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/css'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/plain'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/xml'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/x-component'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/javascript'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/json'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/xml'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/xhtml+xml'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/rss+xml'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/atom+xml'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/vnd.ms-fontobject'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'image/svg+xml'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'image/x-icon'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/x-font-ttf'"
            FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'font/opentype'"
            FilterChain COMPRESS
            FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
        </IfVersion>
      </IfModule>
  </IfModule>

 

 

  • Like 4
  • Thanks 1
Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use