Skip to content

Instantly share code, notes, and snippets.

@boobo94
Last active March 2, 2018 09:51
Show Gist options
  • Save boobo94/6c53a451a2994ecc987c056950a496a1 to your computer and use it in GitHub Desktop.
Save boobo94/6c53a451a2994ecc987c056950a496a1 to your computer and use it in GitHub Desktop.
Most common .htaccess rules

=====[Redirect if no https or www in a single redirect]=====

	RewriteCond %{HTTPS} off [OR]
	RewriteCond %{HTTP_HOST} !^www\.
	RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
	RewriteRule .* https://www.%1%{REQUEST_URI} [L,NE,R=301]

=====[ Remove the slash from the end of URL ]=====

	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule ^(.+)/$ THE_URL/$1 [R=301,L,NE]

NOTES

  • THE_URL = your url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment