1

所以基本上我将所有请求发送到 index.php 所以http://example.com/article等于http://example.com/index.php?page=article

它适用于 mod_rewrite,但对于 IIS7 ( web.config ),它在特定情况下不起作用。

APACHE ( mod_rewrite / .htaccess )

    http://example.com/members .... Works!
    http://example.com/article&id=1 .... Works!

但..

IIS ( web.config )
    http://example.com/members .... Works!
    http://example.com/article&id=1 .... 'Bad Request'

我将如何解决这个问题?

我的 .htaccess

RewriteEngine on

RewriteBase /
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteRule  ^(.*)$ index.php?page=$1 [QSA,L]

我的 web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="Imported Rule 1-1" stopProcessing="true">
                    <match url="^buddy" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="None" />
                </rule>
                <rule name="Imported Rule 1">
                    <match url="^(|/)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="index.php?page={R:1}" appendQueryString="false" />
                </rule>
                <rule name="Imported Rule 2">
                    <match url="^([a-zA-Z0-9/_-]+)(|)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="index.php?page={R:1}" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
        <defaultDocument>
            <files>
                <remove value="iisstart.htm" />
                <remove value="Default.asp" />
                <remove value="Default.htm" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>
4

0 回答 0