【发布时间】:2016-02-08 17:22:11
【问题描述】:
如果有人删除扩展名并添加尾部斜杠,是否可以将页面解析为等效的 .html?
http://www.example.com/page.html
http://www.example.com/page/ 解析到 page.html。
但是,我希望尾部斜杠是可选的,而不是我在 htaccess 中添加的内容。
RewriteEngine on
# render .php as .html
RewriteRule ^(.*)\.html$ $1.php [nc]
# don't need extension on the end
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.html [NC,L]
# .php to .html
RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1.html [L,R=301]
【问题讨论】: