URL Rewrite .htaccess Template for IIS

Today post is about my journey to migrate a MVC php website from a Apache server to an IIS server with PHP Fast CGI module installed.

One of the key differences will be in the usage of .htaccess;
In IIS, the so called .htaccess configuration is using web.config. So we have to find a IIS equivalent of the .htaccess we have for Apache. Thankfully, IIS have a import rule that can partially translate .htaccess rules into web.config. However, not all rules can be successfully imported, especially when you are dealing with wordpress or MVC system that requires URL Rewrite.

After spending some time googling and trial error. I find that, the .htaccess below is the best to be imported that will work for wordpress as well as, php MVC related frameworks (Note: The website I’m migrating is using KISSMVC for php).

Simply copy and paste the codes below, and save it as a text file or .htaccess file. Then goto the target site folder under IIS goto URL Rewrite > Select Import Rule > Select that particular .htaccess file > Apply.

Thats it! Enjoy

# Enable the RewriteEngine.
RewriteEngine On
# When the HTTP request doesn't match and existing file 
# or directory, Rewrite the request and send it to the 
# index.php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]