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。
這工作完美,謝謝! –