【问题标题】:How to create .htaccess rewrite rules in web.config file for godaddy windows hosting plan如何在 web.config 文件中为 Godaddy Windows 托管计划创建 .htaccess 重写规则
【发布时间】:2014-03-11 22:56:51
【问题描述】:

我比较新使用 web.config。我在我的本地主机上创建了 .htaccess 文件,但由于 Windows 托管计划,它无法在 Godaddy 托管上工作。我不知道如何在 web.config 文件中创建重写规则。下面提到了我的 .htaccess 重写规则。 请帮我。谢谢

# Options +FollowSymLinks

RewriteBase /
RewriteEngine on

RewriteRule home$ index.php?page_id=1 [NC]
RewriteRule blog$ index.php?page_id=2 [QSA]
RewriteRule privacy$ index.php?page_id=3 [NC]
RewriteRule contact$ index.php?page_id=4 [NC]

【问题讨论】:

    标签: .htaccess iis mod-rewrite url-rewriting web-config


    【解决方案1】:

    您没有为 IIS 创建.htaccess。如果它没有运行 Apache,它将无法工作。 Web 配置仅适用于运行 IIS 的 Windows。没有什么能让这一切正常工作。您要么必须将其转换为 IIS 重写规则,要么使用 Linux/ApacheWindows/Apache 托管计划。

    尝试在线转换器网站。这是一个可能有效的方法。 http://www.htaccesstowebconfig.com/

    看看这个 web.config 重写是否有效。

    <rule name="rule 1L">
        <match url="home$"  ignoreCase="true" />
        <action type="Rewrite" url="/index.php?page_id=1"  />
    </rule>
    <rule name="rule 2L">
        <match url="blog$"  />
        <action type="Rewrite" url="/index.php?page_id=2"  appendQueryString="true" />
    </rule>
    <rule name="rule 3L">
        <match url="privacy$"  ignoreCase="true" />
        <action type="Rewrite" url="/index.php?page_id=3"  />
    </rule>
    <rule name="rule 4L">
        <match url="contact$"  ignoreCase="true" />
        <action type="Rewrite" url="/index.php?page_id=4"  />
    </rule>
    

    【讨论】:

      【解决方案2】:

      首先清空您的 web.config 文件,请尝试仅复制上述代码并粘贴到您的 web.config 文件中 我希望它会工作...... 您的 web.config 文件必须在根目录中...

      <?xml version="1.0" encoding="UTF-8"?>
      <configuration>
          <system.webServer>
              <rewrite>
                  <rules>
                      <rule name="rule 1f">
                        <match url="home$"  ignoreCase="true" />
                        <action type="Rewrite" url="/index.php?page_id=1"  />
                      </rule>
                      <rule name="rule 2f">
                       <match url="blog$"  />
                       <action type="Rewrite" url="/index.php?page_id=2" ppendQueryString="true" />
                      </rule>
                      <rule name="rule 3f">
                       <match url="privacy$"  ignoreCase="true" />
                       <action type="Rewrite" url="/index.php?page_id=3"  />
                      </rule>
                      <rule name="rule 4f">
                        <match url="contact$"  ignoreCase="true" />
                        <action type="Rewrite" url="/index.php?page_id=4"  />
                      </rule>
                  </rules>
              </rewrite>
          </system.webServer>
      </configuration>  
      

      【讨论】:

      • 与上述类似的情况 - 有人可以确认下面的 webconfig 是否可以工作吗? &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;configuration&gt; &lt;system.webServer&gt; &lt;rewrite&gt; &lt;rules&gt; &lt;rule name="wordpress" patternSyntax="Wildcard"&gt; &lt;match url="*"/&gt; &lt;conditions&gt; &lt;add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/&gt; &lt;add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/&gt; &lt;/conditions&gt; &lt;action type="Rewrite" url="index.php"/&gt; &lt;/rule&gt;&lt;/rules&gt; &lt;/rewrite&gt; &lt;/system.webServer&gt; &lt;/configuration&gt;
      猜你喜欢
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 2013-03-04
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多