Wordpress: Convert .htaccess to web.config file

Everywhere you will find step-by-step guides to migrate from Linux hosting to Windows hosting (or viceversa), but something very useful to know is how to convert .htaccess file to web.config file.

Wordpress has some default rules that writes on Apache .htaccess file.
Something like this below

 # BEGIN WordPress  
 <IfModule mod_rewrite.c>  
 RewriteEngine On  
 RewriteBase /  
 RewriteRule ^index\.php$ - [L]  
 RewriteCond %{REQUEST_FILENAME} !-f  
 RewriteCond %{REQUEST_FILENAME} !-d  
 RewriteRule . /index.php [L]  
 # END WordPress  

The web.config equivalent to this is

 <?xml version="1.0" encoding="UTF-8"?>  
                      <rule name="Main Rule" stopProcessing="true">  
                           <match url=".*" />  
                           <conditions logicalGrouping="MatchAll">  
                                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />  
                                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />  
                           <action type="Rewrite" url="index.php/{R:0}" />  

In this manner you can avoid all 404 errors caused by rewrite absence.

No comments:

Post a Comment