【问题标题】:Window hosting on GoDaddy to redirect index.html to rootGoDaddy 上的窗口托管将 index.html 重定向到根目录
【发布时间】:2016-09-19 17:54:26
【问题描述】:

如果我有 Windows 服务器,是否有可能将我的 index.html 重定向到 root:

www.example.com/index.html    -> www.example.com
http://example.com/index.html -> http://example.com 

我当前使用的主机不是 Apache,我使用的是 Windows 服务器。

【问题讨论】:

    标签: .htaccess redirect windows-hosting


    【解决方案1】:

    又一次修改:

    元刷新标记

    <meta http-equiv="refresh " content="0; url=www.example.com">
    

    如果元刷新标签不起作用,我们可以尝试其他两个选项。

    设置默认文档。 (更简单)

    Web.Config 设置:

    <system.webServer>
    <defaultDocument enabled="true">
        <files>
            <clear />
            <add value="index.html" />
        </files>
    </defaultDocument>
    </system.webServer>
    

    通过 web.config 设置的详细信息:Setting Default WebPage in IIS 7.5

    或通过 IIS UI 设置(如何操作部分中的步骤 1 到 8):https://www.iis.net/configreference/system.webserver/defaultdocument

    在 IIS 中创建重写规则。 (更难)

    如果我们使用 Apache,我们将创建/更新 .htaccess 文件规则:

    RewriteEngine On
    RewriteRule ^index\.html$ / [R=301,L]
    RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]
    

    在 IIS 中,我们必须在 web.config 中以不同的方式添加这些重写规则。请参阅以下链接。

    在 web.config 中创建重写规则的步骤:IIS URL Rewrite and Web.config

    将 .htaccess 内容转换为 IIS web.config 的详细信息:http://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/translate-htaccess-content-to-iis-webconfig

    或在 IIS UI 中创建重写规则:http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

    【讨论】:

    • 嗨..感谢您的回复..我正在使用它,但我的网站不够稳定..它喜欢它不断刷新,并且在网站标签上它总是保持刷新和进步..
    • 您是否打算使用另一个文档来处理根流量,例如 index.php?
    • 我有 2 个文件 index.html 和 index.htm,在文件 index.htm 上。这个文件在指向这个网站的页面中有一些链接..但是在同一个文件 index.htm 我已将其引导回根目录..两者都显示相同的数据,但 index.html 是我们现在的最终结果..所以我必须将 .html 引导回根目录
    • 查看我上面的答案编辑。如果我了解您要做什么,也许重定向到特定的 index.htm 文件会起作用?
    • 你的网站在windows web服务器上的根文件夹的内容是什么?除非您的站点配置为处理无扩展名 url,否则可能有一个索引文件可以自动处理根请求。如果我们可以确定哪个文件处理根请求,也许我们可以直接转发到那个文件。
    猜你喜欢
    • 2017-02-20
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 2018-02-09
    • 2014-05-28
    • 1970-01-01
    • 2012-03-07
    • 1970-01-01
    相关资源
    最近更新 更多