how can I enable mod_rewrite on iis server

2019-02-19 00:30发布

问题:

I found that mod_rewrite function is not enabled on my server(_SERVER["SERVER_SOFTWARE"] -Microsoft-IIS/7.0),Architecture x86 .How can I enabled the mod_rewrite.Could any one please help me.

回答1:

If your hosting at a commercial hosting provider they will most likely have the Microsoft URL Rewrite module installed. This gives you similar functionality to the Apache mod_rewrite module.

To test if this module is installed, create a file called web.config in the root of your website with the content below and try to http://www.domain.com/google where domain.com is your website's domain. If you get redirected to google.com your host has the URL rewrite module installed.

web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="Redirect to google.com" stopProcessing="true">
                    <match url="^google$" />
                    <action type="Redirect" url="http://www.google.com/" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>


回答2:

The answer that worked for me was to install the Microsoft URL Rewrite module and then create a web.config file in the root of the site with this in it (the rules):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Security Rule" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAny">
            <add input="{QUERY_STRING}" pattern="mosConfig_[a-zA-Z_]{1,21}(=|\%3D)" ignoreCase="false" />
            <add input="{QUERY_STRING}" pattern="base64_encode.*\(.*\)" ignoreCase="false" />
            <add input="{QUERY_STRING}" pattern="(\&lt;|%3C).*script.*(\>|%3E)" />
            <add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
            <add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
          </conditions>
          <action type="CustomResponse" url="index.php" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
        </rule>
        <rule name="SEO Rule">
          <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" />
            <add input="{URL}" negate="true" pattern="^/index.php" ignoreCase="false" />
            <add input="{URL}" pattern="(/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$" />
          </conditions>
          <action type="Rewrite" url="index.php" />
        </rule>
      </rules>
    </rewrite>
 </system.webServer>
</configuration>


回答3:

1) find httpd.conf (usually this file can be found in folder callled conf , config or something along those lines)

2) Find and uncomment the line LoadModule rewrite_module modules/mod_rewrite.so

3) Find the line with DocumentRoot “C:/path/to/my/root”, There you will find contents like

Make sure the content inside these two braces looks like

Options All

AllowOverride All

4) All done now restart the Apache server and you will be all good to go



回答4:

There is no free version of mod_rewrite for LINUX available for the Windows OS. The only way out that I found was to import a .htaccess file on IIS using URL REWRITE, which is freely available on the Web Platform Installer.

After installing the URL REWRITE component, follow the steps on the link below to import the .htaccess file and create its windows equivalent, the web.config file.

http://www.iis.net/learn/extensions/url-rewrite-module/importing-apache-modrewrite-rules

Cheers.