【问题标题】:How to stop .htaccess redirect from .html file to a .php file?如何停止 .htaccess 从 .html 文件重定向到 .php 文件?
【发布时间】:2013-06-10 19:20:03
【问题描述】:

我在 GoDaddy 上的“豪华托管”计划中有许多站点,这意味着在根目录下有一个顶级站点,对于每个额外的域,它们的文件都位于根目录中的一个文件夹中。如果您认为以前有人问过这个问题,那么请指导我找到解决方案,因为我找不到确切的答案,尽管我确信它不是新问题。

现在,在根(顶级站点)中有一个 .htaccess 文件,用于在有人输入“index.html”的情况下重定向到“index.php”:

ErrorDocument 404 /404.php

redirect 301 /about.html /about.php
redirect 301 /boat.html /boat.php
redirect 301 /contact.html /contact.php
redirect 301 /charters.html /index.php
redirect 301 /combotrips.html /index.php
redirect 301 /contact-thanks.html /contact-thanks.php
redirect 301 /crew.html /crew.php
redirect 301 /diving.html /key-west-diving.php
redirect 301 /divingcharters.html /key-west-diving.php
redirect 301 /ecocharters.html /eco-tours.php
redirect 301 /fishingcharters.html /key-west-fishing.php
redirect 301 /gallery.html /gallery.php
redirect 301 /index.html /index.php
redirect 301 /packnship.html /key-west-fish-shipped.php
redirect 301 /testimonials.html /testimonials.php
redirect 301 /thefish.html /key-west-fishing.php
redirect 301 /fishing-charters.php /fishing-charter-rates.php


#redirect 301 /Fish%20Availability%20Chart.pdf /docs/key-west-local-fish.pdf

我没有编写 .htaccess 文件。事实上,我并不是很了解 .htaccess 文件。

现在我添加了一个包含子文件夹的新站点。这个新网站是从另一家完全不同的托管公司搬来的。这个新站点有一个 index.html、about.html 等。当我输入“index.html”时,它会立即尝试重定向到 index.php。与 about.php 相同,我认为所有其他 .html 页面尝试重定向到 .php 页面。

在这个新的站点文件夹中,没有 .htaccess 文件。

我确实编写了一个新的 .htaccess 文件,并将 RewriteEngine 离线,但它没有做任何不同的事情。

我怎样才能让这个网站不将 .html 文件重定向到 .php 文件?

更新: 为了让它工作,我把顶层 .htaccess 文件内容的第一行和最后一行都删掉了。我不认为这是 the 答案,而更像是“解决方案”。我不太确定为什么顶级网站一开始就有这些重定向。我从以前的网络公司继承了这个网站。

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    首先,您不需要.htaccess 文件。 .htaccess 文件仅用于在用户可控和受限级别覆盖服务器的httpd.conf 文件,而不允许用户完全控制服务器的配置文件。如果您没有将其用于任何用途,则可以将其删除。

    因为您的 .htaccess 文件中有 301 个重定向,然后它们可能会被您的浏览器缓存(即使您已从 .htaccess 文件中删除它们)。

    要禁用规则,您可以在其前面添加# 注释标记。

    另外你可以删除规则。

    在移除重定向规则之前,服务器会发送重定向的标头请求。一旦它被删除(但它在您的缓存中),您将需要删除浏览器的缓存以使重定向停止发生。

    您可以保留 .htaccess 文件以重写 40​​4 错误处理程序。

    【讨论】:

    • 谢谢!浏览器缓存是最严重的,因为我不知道什么在工作,什么不工作。我必须在三种不同的浏览器中尝试该站点,才能看到删除重定向行确实有效。现在,我认为一切正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多