There is a misconception about the .htacces file and its usefulness in a Windows hosting environment. Normally, this is the file that controls the configuration settings for Linux/UNIX/Apache hosting environments, and its Window’s equivalent is the web.config file. I finally found a use for it the other day, and it’s with WordPress itself. Unfortunately, I didn’t have time to blog about it when I found the fix, and it seems that I am unable to reproduce the problem. But I wanted to at least write about the events that led up to the problem and what I did to fix it to hopefully help reduce the frustration for someone else encountering the same issue. This site is about troubleshooting computer problems after all. And who knows? That someone might be me again after a few months as it’s getting harder to remember things as I age.
The problem was created when I tried to transfer WordPress from one Windows hosting provider to another. Of course, I know each hosting provider is configured differently, and I was running into errors during the move. I finally isolated it to a problem with URL Rewrite. Apparently, the other hosting provider disabled delegation for URL Rewrite, so it broke a lot of my WordPress links. After scouring the Internet, I found the solution, and WordPress will actually tell you the solution. You just need to click on Settings and Permalinks. WordPress will throw some PHP errors, but I never noticed that way at the bottom, it tells you that you need to include some code in the .htaccess file. Basically, it’s to include the mod_rewrite (Linux/UNIX/Apache’s equivalent for IIS’ URL Rewrite) rules. Normally, WordPress will look at the web.config file for rewrite rules in a WIndows environment, but since the hosting provider disabled delegation for it, IIS would error out. This means I couldn’t use them. But once I created an .htaccess file with the mod_rewrite rules and uploaded it, my links started working again. It’s good to know that WordPress will look at the .htaccess file for configuration information if it cannot find it in the web.config file. And I believe here’s the code that you need to add to the .htaccess file to get everything working again:
# 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] </IfModule> # END WordPress