Vă prezentăm mai jos câteva coduri .htaccess pe care le considerăm cele mai uzuale.
- Redirect site fără www. la www.site.ro (cu https:// inclus)
RewriteEngine On RewriteCond %{HTTP_HOST} ^domeniu.ro [NC] RewriteRule ^(.*)$ https://www.domeniu.ro/$1 [L,R=301]
- Detectare iPad și redirectare către varianta de iPad a site-ului
RewriteEngine on RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$ RewriteRule ^(.*)$ https://ipad.domeniu.ro [R=301]
- Custom Error Pages
ErrorDocument 400 /400.html ErrorDocument 401 /401.html ErrorDocument 403 /403.html ErrorDocument 404 /404.html ErrorDocument 405 /405.html ErrorDocument 408 /408.html ErrorDocument 414 /414.html ErrorDocument 500 /500.html ErrorDocument 502 /502.html ErrorDocument 504 /504.html
- Descărcare fișier (nu deschidere în browser)
AddType application/octet-stream .csv AddType application/octet-stream .xls AddType application/octet-stream .doc AddType application/octet-stream .avi AddType application/octet-stream .mpg AddType application/octet-stream .mov AddType application/octet-stream .pdf
- Restricționare acces pe bază de IP
Order deny,allow Deny from All Allow from xxx.xxx.xxx.xxx Allow from yyy.yyy.yyy.yyy
- Activare compresie Gzip
# BEGIN GZIP <ifmodule mod_deflate.c> AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript </ifmodule> # END GZIP
- Redirectare pagină/director
redirect 301 /pagina-veche.php htttps:/www.domeniu.ro/pagina-noua/
- Setare timp de expirare pentru elemente din site
# BEGIN EXPIRES <IfModule mod_expires.c> 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" </IfModule> # END EXPIRES