Options -MultiViews
RewriteEngine On
#1 This line checks if the https is off
RewriteCond %{HTTPS} ^off$
#then, redirect to https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [NC,L,R]
#2 this line checks if the request is /file.html
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
#then redirect /file.html to /file
RewriteRule^/%1 [NC,L,R]
#3 if the request is not for dir
RewriteCond %{REQUEST_FILENAME} !-d
#and the request is an existing filename
RewriteCond %{REQUEST_FILENAME}.html -f
#then rewrite /file to /file.html
RewriteRule ^([^/]+)/?$ $1.html [NC,L]
В приведенном выше примере, первое условие выполняется, когда исходная схема HTTP , а затем правило обрабатывается. HTTP переходит на HTTPS. Первый раунд обработки перезаписи заканчивается здесь.
Во втором раунде mod_rewrite принимает URI /file.html, и правило перенаправляет его в/file, так как/file не существует в каталоге, поэтому нам нужно переписать его в исходный файл # 3. .
Это работает отлично, спасибо! –