.htaccess Snippets

.htaccess Snippets

.htaccess Snippets !

Gli utenti più esperti, che non vogliono installare nessun plugin, possono aggiungere manualmente frammenti di codice nel file .htaccess, per estendere ulteriormente le funzionalità di WordPress.

Ecco alcuni snippets che sicuramente vi faranno comodo !

Note: è importante eseguire prima il backup del file .htaccess, per poterlo ripristinare in caso di problemi. Inoltre, è sempre consigliabile effettuare qualsiasi modifica su uno child theme ovvero un tema “bambino”, in modo che tutte le modifiche apportate non saranno cancellate dagli aggiornamenti futuri del tema originale.

Abilitare la protezione Hotlink

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?bing.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yahoo.com [NC]
RewriteRule \.(jpg|jpeg|png|gif|svg)$ http://dropbox.com/hotlink-placeholder.jpg [NC,R,L

Fonte

Abilitare la compressione gzip

# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

Fonte

Mettere il WWW

(https://www.tuosito.com)

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

Togliere il WWW

(https://tuosito.com)

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

Fonte

Forzare HTTPS tramite .htaccess

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.tuodominio.com/$1 [R,L]

Fonte

Reindirizzare l’intero sito

Redirect 301 / http://newsite.com/

Reindirizzare una singola pagina

Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/

Fonte

Set Expires

# BEGIN EXPIRES

ExpiresActive On
ExpiresDefault “access plus 10 days”
ExpiresByType text/css “access plus 1 week”
ExpiresByType text/plain “access plus 1 month”
ExpiresByType image/gif “access plus 1 month”
ExpiresByType image/png “access plus 1 month”
ExpiresByType image/jpeg “access plus 1 month”
ExpiresByType application/x-javascript “access plus 1 month”
ExpiresByType application/javascript “access plus 1 week”
ExpiresByType application/x-icon “access plus 1 year”

# END EXPIRES

Fonte

Auto UTF-8 Encode

<FilesMatch “\.(htm|html|css|js)$”>
AddDefaultCharset UTF-8
Fonte

Proteggere il file wp-config.php

<files wp-config.php>
order allow,deny
deny from all
</files>

Proteggere il file .htaccess

# Deny access to .htaccess
<Files .htaccess>
Order allow, deny
Deny from all
</Files>

Imperdire la lettura dei files license e readme.

# block access to readme.txt
<files readme.txt >
order allow,deny
deny from all
</files>
# END block access to readme.txt

# block access to licenza.html
<files licenza.html >
order allow,deny
deny from all
</files>
# END block access to licenza.html

# block access to readme.html
<files readme.html >
order allow,deny
deny from all
</files>
# END block access to readme.html


Link utili:

Our website uses cookies and thereby collects information about your visit to improve our website (by analyzing), show you Social Media content and relevant advertisements. Please see our cookies page for furher details or agree by clicking the 'Accept' button.

Cookie settings

Below you can choose which kind of cookies you allow on this website. Click on the "Save cookie settings" button to apply your choice.

FunctionalOur website uses functional cookies. These cookies are necessary to let our website work.

AnalyticalOur website uses analytical cookies to make it possible to analyze our website and optimize for the purpose of a.o. the usability.

Social mediaOur website places social media cookies to show you 3rd party content like YouTube and FaceBook. These cookies may track your personal data.

AdvertisingOur website places advertising cookies to show you 3rd party advertisements based on your interests. These cookies may track your personal data.

OtherOur website places 3rd party cookies from other 3rd party services which aren't Analytical, Social media or Advertising.