简体   繁体   中英

My .htaccess file doesn't work on IIS

I have the following rewrite configuration in my .htaccess file which is working fine in apache server but its not working properly in IIS server.

Options +FollowSymlinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^myservername/$ [NC]
RewriteRule ^(.*)$ http://myservername/$1 [R=301,L]
RewriteRule !\.(php|png|gif|jpg|css|htm|html|txt|js|swf|xml|ico|mp3|csv|wav|mid) /index.php [L,QSA]

How do I get this working on IIS?

IIS doesn't support .htaccess out of the box. To use Apache style mod_rewrite rules on IIS you'll need a third party rewriter such as Iconics ISAPI Rewrite Filter or HeliconTech's ISAPI_Rewrite . You'll probably need to tweak the rewrite rules because not all of mod_rewrite's directives are supported or applicable (because Windows is not Unix).

If you're running IIS7 and it has UrlRewriter installed (which is free) you could use that but you'd need to convert your rewrite rules to a completely different format.

please create new file with name web.config and paste the following

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^.*$" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile"  />                      
                    </conditions>
                    <action type="None" />
                </rule>
                <rule name="Imported Rule 2" stopProcessing="true">
                    <match url="^(.*)$" />
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM