Skip to content

Instantly share code, notes, and snippets.

@bepatrickdavid
Created October 16, 2019 11:59
Show Gist options
  • Select an option

  • Save bepatrickdavid/c353e63f4e40d5af6852f3cb7eb47221 to your computer and use it in GitHub Desktop.

Select an option

Save bepatrickdavid/c353e63f4e40d5af6852f3cb7eb47221 to your computer and use it in GitHub Desktop.

Revisions

  1. bepatrickdavid created this gist Oct 16, 2019.
    26 changes: 26 additions & 0 deletions .htaccess
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <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>