: 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.
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.
More posts by @Connie744
2 Comments
Sorted by latest first Latest Oldest Best
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.
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>
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.