With Microsoft's Web Stack, many PHP applications are now hosted on IIS. As PHP is an open source, one of the advantages of using PHP is that you will find plenty of free script for ready to use. And basically these all ready to use scripts are written for LAMP model, so we might face some problem related to web server (Apache vs IIS) configuration while running these scripts on IIS. Recently one of my friend face similar problem with Apache rewrite rules while he deployed ready to use PHP script on IIS, and asked me to resolve it.
We need to convert apache mod_rewrite rules into IIS URL Rewrite rules to deploy PHP application on IIS. We can accomplish this task in two ways.
Open .htaccess file of PHP and manually convert each apache mod_rewrite rule in IIS URL Rewrite rule and then save it in web.config. Now loop through above process for total number of apache mod_rewrite rule ;)
Instead of manually loop through each apache mod_rewrite rule and converting it in IIS URL Rewrite rule, we can automate this process with IIS URL Rewrite Module. Earlier in one post we have seen how we can use IIS URL Rewrite Module to set preferred domain. Following is the steps for converting apache mod_rewrite rules into IIS URL Rewrite rules.
Open URL Rewrite Module in IIS.
In Actions pane of right side, click on import rules. It will open Import mod_rewrite rules screen.
Browse through .htaccess file and click on import button.
You can see summary of converted rules in tree view. You can also verify converted rules in XML view.
After verifying each rule click on apply in Actions pane.
That’s it, you have done. Now your all apache mod_rewrite rules are converted in IIS URL Rewrite rule and saved in web.config.