Posted on • Updated on

.htaccess cheatsheet

author

Kai

#Note

Before making any changes to the .htaccess file must check RewriteEngine  is set to On

RewriteEngine On

#Redirect Browser to HTTPS

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
#OR
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

#Redirect Browser to HTTP

RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

#Set the Time Zone

SetEnv TZ Asia/Kolkata 

#Remove the www from your URL.

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

#Custom Error Pages

ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html

#Set DirectoryIndex

DirectoryIndex index.php

configure multiple index files as a fallback.

DirectoryIndex index.php index.html index.htm
end of article

Related Posts

Join Our Newsletter

Want the latest & greatest from our blog straight to your inbox with some exclusive offers from our partners and sponsors?

We won't spam. Promise.