[英]htaccess to resolve a trailing slash to .html page
Is it possible to resolve a page to it's .html equivalent if someone removes the extension and adds a trailing slash? 如果有人删除扩展名并添加斜杠,是否可以将页面解析为等效于.html的页面?
http://www.example.com/page.html http://www.example.com/page.html
http://www.example.com/page/ <-- adding trailing slash resolve to page.html. http://www.example.com/page/ <-在page.html中添加斜杠解析。
However, I want the trailing slash to be optional and not something that I add in htaccess. 但是,我希望斜杠是可选的,而不是我在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]
Have it like this: 像这样:
RewriteEngine On
# .php to .html
RewriteCond %{THE_REQUEST} \ /(.+)\.php[?\s] [NC]
RewriteRule ^ /%1.html [L,R=301]
# don't need extension on the end
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^(.+)\.html/?$ $1.php [L,NC]
Make sure to clear your browser cache before testing this change. 在测试此更改之前,请确保清除浏览器缓存。
To make the trailing slash optional for html requests, you can use : 要使尾部斜杠对于html请求是可选的,可以使用:
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)/?$ $1.html [NC,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.