Search code examples
phpiisurl-rewriting

Wordpress 500 (URL Rewrite Module Error.)


I am hosting a Wordpress website in IIS 8 I am getting the following error:

Failed to load resource: the server responded with a status of 500 (URL Rewrite Module Error.)

When I upload a new image and display. If I go to wp-content and give IIS_USRS access then the image works, when I add a new image I have to remove IIS_USRS and add it again for the image to work

If I use the following web config the website never loads

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
  <rules>
    <rule name="wordpress" patternSyntax="Wildcard">
      <match url="*" />
        <conditions>
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
      <action type="Rewrite" url="index.php" />
    </rule>
  </rules>
</rewrite>


Solution

  • Use these below mentioned RULEs in your web.config file:

    <rules>
    
        <rule name="Imported Rule 1" stopProcessing="true">
            <match url="^index\.php$" ignoreCase="false"/>
            <action type="None"/>
        </rule>
    
        <rule name="Redirect Image to HTTP" stopProcessing="true">
            <match url=".*\.(gif|jpg|jpeg|png|css|js)$" ignoreCase="true"/>
            <action type="Rewrite" url="{R:0}"/>
        </rule>
    
        <rule name="Imported Rule 2" stopProcessing="true">
            <match url="." ignoreCase="false"/>
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true"/>
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true"/>
            </conditions>
            <action type="Rewrite" url="/index.php"/>
        </rule>
    
    </rules>