【发布时间】:2017-05-22 20:21:48
【问题描述】:
我正在尝试隐藏我网站的 .html 扩展名 我使用下面在 StackOverflow 上找到的以下代码来执行此操作
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
这适用于每个页面(about.html、contact.html 都被隐藏)除了 blog.html
所以基本上,mydomain.com/blog 给了我以下错误;
You don't have permission to access /blog/ on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
这是一个 HTML 文件,位于根文件夹中,就像联系人和 about 一样。但有来自子文件夹的链接(其中包含博客页面 HTML)。所以我猜问题出在那个地方?
另外,如果我直接访问博客文章 (mydomain.com/blog/post1.html),它会起作用并隐藏 .html
我搜索了很多,但找不到解决方案。我该如何解决这个问题?
非常感谢。
My document order
- .htaccess
- about.html
- blog.html [only file that gives 403 error]
- blog (folder)
- post1.html
- post2.html
【问题讨论】:
-
您遇到了与目录斜线相关的问题。使用 htaccess DirectorySlash off 中的以下行关闭目录斜杠