The htaccess required for the website | blog community

    Htaccess snippets required for the website

    Hello friends! congdongblog brings you useful things related to the website again, Here I share you guys htaccess required for the website that I am in the process of working.

    I noted all of them below, but inserted directly into the file .htaccess.

    Note: Make sure you copy the right file and put the right file in the right folder, be careful with this .htaccess file because it can kill your website, The wrong sign when wrong or wrong copy is your website showing 1 white, that's due to the problem with your htaccess file

    How to fix it when: You go directly to the host or vps where you store your source code, you go right in your main directory there will be a .htaccess file you can edit it again.

    And here are the necessary htaccess paragraphs that you should proceed to do, wish you success: p

    • Using gzip can help your website be compressed to a minimum level so visitors will spend less time downloading.

    # Start gzip compression 
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    # End Gzip compression

    • When the browser has already cached those files, the next time it loads, it does not have to download data so you will be able to access it faster.

    # Browser caching

    ExpiresActive On
    ExpiresByType image/jpg "access 1 year"
    ExpiresByType image/jpeg "access 1 year"
    ExpiresByType image/gif "access 1 year"
    ExpiresByType image/png "access 1 year"
    ExpiresByType text/css "access 1 month"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType application/x-javascript "access 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresDefault "access 2 days"

    # End Browser caching

    • Speed ​​up image loading time with cache

    ExpiresActive On
    ExpiresDefault A2592000

    • Gzip compression will minimize response time by reducing the download size from the HTTP protocol.


    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript

    # END GZIP

    • Browse Caching means that it will create a cached version of a website and save it to your computer, since subsequent visits the browser will bring data in this cache to execute without having to reload one. again.

    # BEGIN Expire headers

    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"

    # END Expire headers
    # BEGIN Cache-Control Headers

    Header set Cache-Control "public"

    Header set Cache-Control "public"

    Header set Cache-Control "private"

    Header set Cache-Control "private, must-revalidate"

    # END Cache-Control Headers

    • Preventing server bandwidth theft

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)? (NC)
    RewriteRule .(jpg|jpeg|png|gif)$ - (NC,F,L)

    Remember to replace your domain! place yourdomain.

    • Keep-Alive speeds up requests and reduces requests

    Header set Connection keep-alive

    What is Keep-Alive, you can find out through this article

    What is Keep-Alive? how to install and use

    Above is the htaccess code needed for the website, you can copy the file .htaccess in the source, or in a custom theme. If you have any questions join the group congdongblog I will support you all!

    Không có nhận xét nào