我想用最少量的重定向来实现以下目标;.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) –