获取html5样板文件.htaccess文件以在dreamhost网站

时间:2015-12-12 07:44:07

标签: html5 apache .htaccess mod-rewrite dreamhost

完全是Apache新手。

尝试删除" .html"通过添加以下行(找到here)来扩展网址:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.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 ^([^\.]+)$ $1.html [NC,L]

</IfModule>

但.html扩展名仍保留在可见网址中。

我无法找到关于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/$1 [L,R=301]

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

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

请注意上面的代码可能会导致新问题,因为它会导致我的某个页面返回403 Forbidden错误,但我认为这是另一个与我原始问题无关的问题所以我认为这是一个问题当我在其他地方找到解决方案时解决并将修复上述代码。

符号链接似乎无关紧要。

.htaccess文件位于&gt; mySite.com目录中,而不是包含此目录的目录

1 个答案:

答案 0 :(得分:0)

DreamHost wiki有how to use Apache redirects and rewrites的指南。该指南提到了FollowSimylinks

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