Skip to content

Instantly share code, notes, and snippets.

@zspine
Last active July 6, 2019 02:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zspine/23aaad169de5a2bfe2df to your computer and use it in GitHub Desktop.
Save zspine/23aaad169de5a2bfe2df to your computer and use it in GitHub Desktop.
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
Copy link

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