【问题标题】:.htaccess in hosting Windows.htaccess 在托管 Windows
【发布时间】:2018-12-15 07:31:12
【问题描述】:

我最近购买了一个带有 Windows (IIS) 的虚拟主机。 我必须转移到托管的网站使用以下 .htaccess 文件

    Options -Indexes

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico

  RewriteRule ^(.*)(\.)(.*)$ index.php?url=$1.$3 [L,QSA]
  RewriteRule ^ajax$ _res/ajax.php [QSA]
  #RewriteRule ^(.*)$ index.php?t=$1 [L,QSA]
</IfModule>

在使用IIS的新服务器上无法正常工作,我该如何解决?

【问题讨论】:

标签: .htaccess iis hosting


【解决方案1】:

在您的网站 web.config 文件中,在 system.webServer 部分下添加 rewrite 部分,如下所示:

<system.webServer>
        <rewrite>
            <rules>
                <rule name="Rule 1" stopProcessing="true">
                    <match url="^(.*)(\.)(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                        <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php?url={R:1}.{R:3}" appendQueryString="true" />
                </rule>
                <rule name="Rule 2">
                    <match url="^ajax$" ignoreCase="false" />
                    <action type="Rewrite" url="_res/ajax.php" appendQueryString="true" />
                </rule>
                <rule name="Rule 3" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <action type="Rewrite" url="index.php?t={R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

另外,请确保您的服务器上安装了Url Rewrite IIS 扩展。

【讨论】:

    猜你喜欢
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 2012-09-28
    • 2012-04-07
    • 1970-01-01
    • 2016-03-08
    相关资源
    最近更新 更多