【发布时间】:2019-07-31 11:05:12
【问题描述】:
第一个问题。所以我在 Apache 上有一个简单的网站“website.com”:
website.com
index.html
site1.html
site2.html
在每个 html 中,我都有指向其他的链接,格式如下:
<a href="index.html">main</a>
<a href="site1.html">site1</a>
<a href="site2.html">site2</a>
我希望浏览器显示“website.com/site1”而不是“website.com/site1.html”。
我已经玩了几天了,我总是得到以下结果之一:
- 无限循环的重定向。
- 内部服务器错误。
- 两个版本都有效(例如“website.com/site1.html”和“website.com/site1”),但 .html 保留在地址栏中。
我不知道发生了什么。我什至无法正确打破它。例如,我预计这个 .htaccess 会在访问“website.com/site1”时抛出错误,因为没有规则将 site1 重定向到 site1.html:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [R=302,QSA]
但不行 - 它有效,只是不会删除地址栏中的 .html。
Apache 如何知道在没有适当的 RewriteRule 的情况下将“website.com/site1”重定向到“website.com/site1.html”?我的理解是否错误,我必须从 website.com/site1 重定向到 website.com/site1.html 才能使其正常工作?
提前致谢。
【问题讨论】:
标签: html apache .htaccess mod-rewrite