获取 html5 样板 .htaccess 文件以在 dreamhost 站点上工作

getting html5 boilerplate .htaccess file to work on dreamhost site

对 Apache 完全陌生。

尝试通过添加以下行(找到 here)从 url 中删除“.html”扩展名:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .html [NC,L]

至此(包括 ^ 现在的那些行):

<IfModule mod_rewrite.c>

RewriteEngine On

# Enable the `FollowSymLinks` option if it isn't already.
# Options +FollowSymlinks

# If your web host doesn't allow the `FollowSymlinks` option, you need to comment it out or remove it, and then uncomment the `Options +SymLinksIfOwnerMatch` line, but be aware of the performance impact.
# Options +SymLinksIfOwnerMatch

RewriteBase /

# RewriteOptions <options>

RewriteCond %{HTTPS} =on
RewriteRule ^ - [env=proto:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^ - [env=proto:http]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .html [NC,L]

</IfModule>

但是 .html 扩展名保留在可见的 url 中。

我找不到关于 Dreamhost 是否允许 FollowSymLinks 的任何信息,但我尝试启用它,以及 SymLinksIfOwnerMatch,我也尝试禁用 RewriteBase / 甚至删除mod 重写 if 语句。我将文件放在我网站的根目录中,并尝试将它放在父文件夹中,但没有结果。有人知道我做错了什么吗?

The full .htaccess is here.

已解决:

我仍然不知道为什么上面的代码不起作用,但我只是使用了 Dreamhost's wiki 中的代码:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\ HTTP/
    RewriteRule ^(.*)index$ http://Your_Site_Url_Goes_Here.com/ [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/$ http://Your_Site_Url_Goes_Here.com/ [L,R=301]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+)\.html\ HTTP/
    RewriteRule ^(.+)\.html$ http://Your_Site_Url_Goes_Here.com/ [L,R=301]
    RewriteRule ^([a-z]+)$ /.html [L]
</IfModule>

请注意,上面的代码可能会导致新问题,因为它会导致我的一个页面出现 return 403 禁止错误,但我认为这是与我最初的问题无关的另一个问题,所以我认为这是一个解决方案,当我在其他地方找到解决方案时会修复上面的代码。

符号链接似乎无关紧要。

.htaccess 文件进入 >mySite.com 目录,而不是包含此目录的目录

DreamHost wiki 在 how to use Apache redirects and rewrites 上有一个指南。该指南提到 FollowSimylinks

您还应该检查 Apache 错误日志以查看失败的原因(并编辑您的问题以更具体地说明您在浏览器中看到的结果)。