D
D
dimanche2019-12-19 13:07:24
HTML
dimanche, 2019-12-19 13:07:24

How to compose correct htaccess for website html site?

You need to create an htaccess with the following properties

  • Redirect from www to non-www
  • Removing at the end of .html + redirect
  • Removing index.html
  • 404 error file path
  • Redirect from http to https

All redirects work correctly, but if I add a redirect to https, it redirects too many times
My htaccess:
AddDefaultCharset utf-8

ErrorDocument 404 /404.html

RewriteEngine On

# редирект с www
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]

# Делаем редирект со слешем на без слеша
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]

# Убираем html 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^.*$ $0.html [L,QSA]
RewriteCond %{THE_REQUEST} ([^\s]*)\.html(\?[^\s]*)?
RewriteRule (.*) %1 [R=301,L]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FeST1Val, 2019-12-19
@dimanche

Try it:

# HTTP -> HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question