Created
October 16, 2019 11:59
-
-
Save bepatrickdavid/c353e63f4e40d5af6852f3cb7eb47221 to your computer and use it in GitHub Desktop.
.htaccess: rewrite html extension and redirect to subfolder lang
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
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
# redirect to subfolder /it if language is it | |
RewriteCond %{HTTP:Accept-Language} ^it [NC] | |
RewriteRule ^/?$ https://domain.com/it/ [R,NC,L] | |
# remove the .html extension | |
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP | |
RewriteRule (.*)\.html$ $1 [R=301] | |
# remove index and reference the directory | |
RewriteRule (.*)/index$ $1/ [R=301] | |
# remove trailing slash if not a directory | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{REQUEST_URI} /$ | |
RewriteRule (.*)/ $1 [R=301] | |
# forward request to html file, **but don't redirect (bot friendly)** | |
RewriteCond %{REQUEST_FILENAME}.html -f | |
RewriteCond %{REQUEST_URI} !/$ | |
RewriteRule (.*) $1\.html [L] | |
# redirect http to https set on the server panel (cpanel/plesk) | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment