WordPress permalinks on IIS 7.0

As I mentioned earlier, one of the problems I have faced during migration of my blog to IIS was getting permalinks to work. Actually, in most cases users should not face any problems with that – WordPress has already prepared a guide to get the permalinks working under IIS. It should work in most cases. Unfortunately, my case was a bit different.

Thing was that my WordPress is not installed on the root of my host. I wanted to preserve the same strategy I used on my older (Linux) host:reteks

So, I copied WordPress setup to the /blog/ subdirectory, added blog.dabasinskas.net and dabasinskas.net to the list of bindings of the site and then added the following lines to web.config file on the root of my host (one level above /blog/ directory):

That worked well. I was able to access the blog via blog.dabasinskas.net URL and install it without any issues. Unfortunately, I saw issues once I tried enabling the permalinks and accessing default post. It resulted in 404/Not Found error.

The actual issue was that rewrite rules created by WordPress in /blog/web.config file were not being processed. That is because they were applied only when URL contained /blog/ folder and since I was accessing my blog via blog.dabasinskas.net that was not the case.

So, what I did was moving WordPress rewrite rules to the web.config file on the root of the site. After doing that, the file contents looked like this:

That helped and I though there are no issues left. Unfortunately, it did not take long until I found out that login page was not working.

The issue with login page was that once correct credentials were entered, I was being redirected back to the login box with a note that my credentials were incorrect. Also, I saw URL contained reauth=1 parameter and location I was being redirected contained /blog/ inside while it should not.

Guessing that WordPress determinate that path by physical location it is installed on and that is where the problem is, I added the following lines to my /blog/web.config file:

No big surprise – it solved the issue. And actually, it did more then that. Since I do not want anyone accessing my blog via /blog/ subfolder, guys doing that will be automatically redirected to blog.dabasinskas.net. Also, since it uses permanent redirect (302), it will help for SEO by avoiding duplicate content.

Once those three rewrite rules listed above were added to the site, I have not noticed any more issues related to URLs. If you have noticed any of them, please let me know by leaving a comment below.


4 comments on the post

  1. I’ve been trying to get the same situation setup and this worked perfectly.
    Thanks so much for posting your solution!

Leave a Reply

Your email address will not be published. Required fields are marked *