Mobile app version of vmapp.org
Login or Join
Connie744

: What is the IIS equivalent of a rewrite rule that sends all requests to a PHP file? I've always used Apache for all my web development work and I'm struggling to get my head around IIS.

@Connie744

Posted in: #Iis #Iis7 #IsapiRewrite #ModRewrite #UrlRewriting

I've always used Apache for all my web development work and I'm struggling to get my head around IIS. I've got an API that re-routes all requests to one particular file: 'api.php', how would I do the following in IIS:

RewriteEngine on
RewriteRule ^/.* /api.php


My server only allows web.config files to achieve this so I have no access to IIS manager, or anything of that nature. I'm using IIS 7.5.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Connie744

2 Comments

Sorted by latest first Latest Oldest Best

 

@Shelton105

First Method :

Install web platform installer from: www.iis.net/downloads
Find the urlrewrite and add to IIS, then you can find URL rewrite section in IIS.

You can create a new rule or import from .htaccess file via URL rewrite.

Second and Easy Method :


Open IIS and select related website
Go to errors section and find 404 error.
Double click on it.
Change URL to /index.php


Now all unknown requests redirect to index.php.

10% popularity Vote Up Vote Down


 

@Megan663

The design pattern you are using is called the "front controller" -- a central entry point for handling requests.

Here is a website that shows how to implement that pattern with various webservers. Here is the configuration they recommend for IIS in the web.config file:

<?xml version="1.0"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Silex Front Controller" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme