【发布时间】:2018-04-14 07:48:54
【问题描述】:
我正在尝试从 .html 切换到无扩展名文件。我也在使用 MAMP,所以我可以离线测试它,所以我在代码中需要输入斜杠而不是 example.com。我在所有文件名上都有 .html,但在所有菜单链接中都有无扩展名的 url,最后没有斜杠。当我输入 localhost/example.html 时,它会恢复为应有的 localhost/example,如果我单击菜单中的某个项目,它会转到删除 .html 的正确页面,当我拼错某些内容时,它会转到 404 页面应该的。但是,它不会在目录中拾取页面。有人可以告诉我需要改变什么吗?
ErrorDocument 404 /missing.html
AddHandler server-parsed .html
#
Options +FollowSymLinks +Includes
RewriteEngine on
#
#External redirect for extensionless url
RewriteCond %{THE_REQUEST} \.html
#While on Localhost http://www.example.com is removed before / slash in the following
RewriteRule ^(.+)\.html$ /$1 [R=301,L]
#
# Internal rewrite for extensionless url
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /$1.html [L]
#
【问题讨论】:
-
如果我理解正确,当您输入 localhost/directory/example.html 时,您需要 localhost/directory/example 才能工作?
-
由于某种原因,当我没有更改任何内容时,它现在可以正常工作。我可以去 localhost/directory/example 并且页面加载正确。但是,当我从该目录页面单击菜单中的一个项目时,它会为 css 文件等抛出一堆 404。我认为这是由于在本地主机上时无法在包含中使用完整的 url。你知道在本地主机上的解决方法吗?