1 June
2022
.htaccess Cheat Sheet
Quick tips for common .htaccess rules.
No lengthy descriptions, just a bunch of handy code snippets.
1 2 3 4 |
<IfModule mod_rewrite.c> RewriteEngine on # rewrite rules go here </IfModule> |
1 2 |
RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
1 2 3 4 |
RewriteCond %{HTTP_HOST} !^$ RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTPS}s ^on(s)| RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] |
1 |
RewriteRule (.*) https://www.example.com/ [R=301,L] |
1 2 3 |
<FilesMatch ".+\.ph(ar|p|tml)$"> SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost" </FilesMatch> |
1 |
RewriteRule ^(config|tmp)\/|^\.|^/\. - [R=404] |
1 2 3 4 5 |
SetEnvIfNoCase User-agent (MJ12bot) bad-bot=1 SetEnvIfNoCase User-agent (SemrushBot) bad-bot=1 Order Allow,Deny Allow from ALL Deny from env=bad-bot |