在IIS 7.5上重定向旧的PHP页面

Apologies if this has already been covered. It seems redirecting/rewriting URLs is easy, hosting PHP is easy, but redirecting PHP on IIS is a bit of a pain. Basically I am trying on a IIS server to redirect requests for any php page to default.aspx

I believe the main problem is that out-of-the-box IIS doesn't want to serve PHP.

Steps that I covered so far include

  • Writing a rewrite rule that does a regex match on any php file and pass it to default.aspx
  • Adding *.php to the handlers and using the same one defined for *.aspx
  • Restarting the server
  • Hitting head against brick wall

I don't want to have to install FastCGI or equivalent just to do this - I just want to be able to handle any php pages that used to reside on the domain and point them at default.aspx

Any suggestions/advice welcome!

Have you tried the web.config.txt this is like .htaccess on an APACHE server. I don't know what your trying to rewrite, but here is a simple template to get you started.

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^carlosag.net$" />
          </conditions>
          <action type="Redirect" url="http://www.carlosag.net/{R:0}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

The basic PHP redirection function used for this purpose is header, you can check it in the manual.

http://php.net/manual/en/function.header.php

Basically is:

header('Location: http://iis.default.com/home.aspx');