1

我需要帮助将 htaccess 转换为 IIS 服务器的 web.config。
这个 htaccess 被 Modx Evolution 1.x 使用

#php_flag register_globals Off
#AddDefaultCharset utf-8
#php_value date.timezone Europe/Moscow

Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]

# Rewrite domain.com -> www.domain.com -- used with SEO Strict URLs plugin
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
#RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# Exclude /assets and /manager directories and images from rewrite rules
RewriteRule ^(manager|assets)/*$ - [L]
RewriteRule \.(jpg|jpeg|png|gif|ico)$ - [L]

# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

我需要将此配置转换为 IIS 服务器的 web.config。

4

1 回答 1

1

将其作为web.config放在您的网络服务器的根文件夹中,将 example.com 更改为您的域名:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <directoryBrowse enabled="false" />
        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
                <add value="Default.htm" />
                <add value="Default.asp" />
                <add value="index.htm" />
                <add value="Default.aspx" />
            </files>     
        </defaultDocument>
        <rewrite>
            <rules>
                <rule name="Add WWW prefix" >
                  <match url="(.*)" ignoreCase="true" />
                    <conditions>
                      <add input="{HTTP_HOST}" pattern="^example\.com" />
                    </conditions>
                  <action type="Redirect" url="http://www.example.com/{R:1}"
                    redirectType="Permanent" />
                </rule> 

                <rule name="ModX IIS7 Rule 1" stopProcessing="true">
                    <match url=".*" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_USER_AGENT}" pattern="^.*internal\ dummy\ connection.*$" />
                    </conditions>
                    <action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
                </rule>
                <rule name="ModX IIS7 Rule 2" stopProcessing="true">
                    <match url="^(manager|assets)" ignoreCase="false" />
                    <action type="None" />
                </rule>              
                <rule name="ModX IIS7 Rule 3" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" pattern="" ignoreCase="false" />
                    </conditions>
                    <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>          
    </system.webServer>
</configuration>
于 2012-11-05T08:20:49.093 回答