托管中的 .htaccess Windows

.htaccess in hosting Windows

我最近购买了一个带有 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=. [L,QSA]
  RewriteRule ^ajax$ _res/ajax.php [QSA]
  #RewriteRule ^(.*)$ index.php?t= [L,QSA]
</IfModule>

在使用IIS的新服务器上无法运行,如何解决?

在您的网站 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 扩展。