Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web.config redirect all paths to index.php - not working

I predominantly work with Apache and .htaccess, but I am currently working on a site that is hosted on a Windows server. The Web.config is causing me a lot of problems.

I am trying to redirect all the URL requests to the index.php so that the PHP script can then parse the URL and serve up the correct page.

The .htaccess (which works fine on Apache) is as follows:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [NC,L]
RewriteRule ^(.*)$ /index.php [NC,L]

The Web.config rewrite (which doesn't want to work):

    <rewrite>
        <rules>
            <rule name="rule 1G" stopProcessing="false">
                <match url="^(.*)$"  ignoreCase="true" />
                <action type="Rewrite" url="/-"  />
            </rule>
            <rule name="rule 2G" stopProcessing="false">
                <match url="^(.*)$"  ignoreCase="true" />
                <action type="Rewrite" url="//index.php"  />
            </rule>
        </rules>
    </rewrite>

Here is the site on my Apache testing server: http://villasilvana.hotmintmedia.com And here on the live Windows server: http://www.villasilvana.net (UPDATE - I've had to revert the live site back to the original, as it is still in use)

I have trawled through countless pages on ISS and Web.config and tried many variations on the rewrite code, none of which have worked. I would appreciate any help.

like image 342
Adam Avatar asked Jan 09 '14 00:01

Adam


1 Answers

I know it's a bit late in the day, but in case anyone else is looking

<!--web.config url rewrite-->
<configuration> 
  <system.webServer>
      <rewrite>
          <rules>
              <rule name="Redirect To Index" stopProcessing="true">
                  <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>
  </system.webServer>
</configuration>
like image 125
mightymephisto Avatar answered Nov 19 '22 15:11

mightymephisto