Skip to content

Instantly share code, notes, and snippets.

@w-jerome
Last active August 31, 2022 00:34
Show Gist options
  • Select an option

  • Save w-jerome/085f41be5e956f874a36697015352733 to your computer and use it in GitHub Desktop.

Select an option

Save w-jerome/085f41be5e956f874a36697015352733 to your computer and use it in GitHub Desktop.
HTACCESS - Tips
# Doc: https://www.askapache.com/htaccess/ssl-example-usage-in-htaccess/#rewrite-http-to-https-no-mod_ssl
RewriteEngine on
# REMOVE TRAILING SLASH
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)/(.*)/$ /$1/$2 [L,R=301]
# END REMOVE TRAILING SLASH
# https and www for OVH
RewriteCond %{ENV:environment} production
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{ENV:environment} production
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirection domaine with www
RewriteCond %{HTTP_HOST} ^site\.fr
RewriteRule (.*) http://www.site.fr/$1 [R=301,L]
# Redirection du domaine avec www
RewriteCond %{HTTP_HOST} !^www\.site\.com$ [NC]
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteCond %{REMOTE_ADDR} !^::1
RewriteRule ^(.*)$ https://www.site.com/$1 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment