【发布时间】:2016-10-17 15:26:54
【问题描述】:
我有一个网站,例如: https://website.com
它将页面加载为:
https://website.com/page1.html
https://website.com/page2.html
https://website.com/page3.html
https://website.com/page4.html
我想打开除了page2.html之外没有扩展名的以上页面,即:
https://website.com/page1
https://website.com/page2.html
https://website.com/page3
https://website.com/page4
如果用户明确输入:
https://website.com/page1.html
那么也应该重定向到:
https://website.com/page1
page3 和 page4 相同
我在 .htaccess 中应用了以下规则:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
它可以打开没有扩展名的页面,即:
https://website.com/page1
https://website.com/page2
https://website.com/page3
https://website.com/page4
但是当我进入时:
https://website.com/page1.html
它被打开了,但我需要的是,当我打开时:
https://website.com/page1.html
应该会自动重定向到
https://website.com/page1
这个条件应该适用于除page2.html之外的所有页面
提前感谢您的帮助。
【问题讨论】:
标签: apache .htaccess mod-rewrite url-rewriting url-redirection