我想用最少量的重定向來實現以下目標;.htaccess - 刪除www,強制https,刪除php並刪除尾部斜槓
- 刪除WWW
- 力HTTPS
- 刪除PHP擴展
- 刪除結束斜線
我有什麼事這麼遠,是工作:
RewriteEngine On
# REMOVE WWW
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# FORCE HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# REMOVE TRAILING SLASH
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# REMOVE PHP EXTENSION
RewriteRule ^(.+)\.php$ /$1 [NC,L,R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)/?$ /$1.php [END]
當前行爲:
http://www.example.com/functions.php -> https://example.com/functions
(含4個重定向作品)
OR
http://www.example.com/functions/ -> https://example.com/functions
(含4個重定向作品)
沒有人有任何建議,如何使盡可能少的重定向這項工作?
[獲取.htaccess文件的可能的複製工作中子文件夾](http://stackoverflow.com/questions/27642401/getting-htaccess-file-to-work-in-subfolders) –