Skip to content

Instantly share code, notes, and snippets.

@zspine
Last active Jul 6, 2019
Embed
What would you like to do?
htaccess cheatsheet
#Hide directories and files
Options -Indexes
#Set Enviroment Varaibles
SetEnv APPLICATION_ENV "development"
# Enable the rewrite engine
RewriteEngine On
# redirect non www to www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Forece SSL and the www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
@larsonreever

This comment has been minimized.

Copy link

@larsonreever larsonreever commented Apr 23, 2019

Thanks, this will surely help. i would like to add on to this, here you can find various htaccess exploits , types of htaccess hack attacks alongwith snippets and how to clean up the hack. I am sure this will be a handy resource to go alongwith - https://secure.wphackedhelp.com/blog/wordpress-htaccess-hacked-exploit-cleanup/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment