Last active
April 1, 2020 07:27
-
-
Save w1cerg/d57cf27c7d45fcde2bc5add6afe129d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### use blank image instead of missing picture | |
# | |
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f | |
RewriteRule \.(gif|jpe?g|png|bmp) /local/images/blank.gif [NC,L] | |
### Redirect to https | |
# | |
RewriteCond %{HTTPS} off | |
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
### Redirect to https with exceptions | |
# | |
RewriteCond %{HTTPS} off | |
RewriteCond %{REQUEST_URI} !^/bitrix/tools/ | |
RewriteCond %{HTTP:X-Forwarded-Proto} !https | |
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
### Deny all files except index.php and / | |
### Don't have affect on .txt, .jpg etc if they render by nginx | |
# | |
Order allow,deny | |
Deny from all | |
<FilesMatch ^(index\.php)?$> | |
Allow from all | |
</FilesMatch> | |
###### Always one redirect instead two/three sequential redirects | |
###### www.domain.com -> domain.com, domain.com/page -> domain.com/page/, http -> https | |
# | |
### www. + without ending / | |
# | |
RewriteCond %{REQUEST_URI} !\? | |
RewriteCond %{REQUEST_URI} !\& | |
RewriteCond %{REQUEST_URI} !\= | |
RewriteCond %{REQUEST_URI} !\. | |
RewriteCond %{REQUEST_URI} !\/$ | |
RewriteCond %{HTTP_HOST} ^www\.(.*)$ | |
RewriteRule ^(.*)$ https://%1/$1/ [L,R=301] | |
# | |
### www. + with ending / | |
# | |
RewriteCond %{REQUEST_URI} !\? | |
RewriteCond %{REQUEST_URI} !\& | |
RewriteCond %{REQUEST_URI} !\= | |
RewriteCond %{REQUEST_URI} !\. | |
RewriteCond %{REQUEST_URI} ![^\/]$ | |
RewriteCond %{HTTP_HOST} ^www\.(.*)$ | |
RewriteRule ^(.*)$ https://%1/$1 [L,R=301] | |
# | |
# Without www. + without ending / | |
# | |
RewriteCond %{REQUEST_URI} !\? | |
RewriteCond %{REQUEST_URI} !\& | |
RewriteCond %{REQUEST_URI} !\= | |
RewriteCond %{REQUEST_URI} !\. | |
RewriteCond %{REQUEST_URI} !\/$ | |
RewriteCond %{HTTP_HOST} ^([^www].*)$ | |
RewriteRule ^(.*)$ https://%1/$1/ [L,R=301] | |
# | |
### http -> https | |
# | |
RewriteCond %{HTTPS} off | |
RewriteCond %{REQUEST_URI} !^/bitrix/tools/ | |
RewriteCond %{HTTP:X-Forwarded-Proto} !https | |
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment