Saturday, May 2, 2009

Resolving 403 Forbidden Page Error For WordPress Blogs


Well, sometime back I moved my blog from blogspot to WordPress using WordPress's awesome Importer tool. The action was mainly driven by the desire to host the blog on my own domain since that gives me a lot more flexibility to customize stuff as I want it to be. Luckily for me, my hosting provider (A2hosting) has a ready installation package for setting up a WordPress blog and so that part went pretty smooth. However, once I tried to open up the landing page of my blog, I got page forbidden (403) error. Incidentally, it was coming for every single page of the blog, including the wp-admin.

After a lot of hassle, I was finally able to resolve it and everything seems to be working alright since then. Anyhow, I thought of putting down my observations here for anyone who may face similar issue with their installations or otherwise.

- The obvious things first - I checked the permissions on the installation folder (for me, /blog) and found it to be perfectly ok (755 for read / execute to world).

- Next I checked the .htaccess in the root and so I found the problem. I had an earlier rails (Ruby on Rails) installation and following lines were present in it: -

<br /><em>RewriteEngine on</em></p><p><em>RewriteCond %{HTTP_HOST} ^sushain.com$ [OR]</p><p>RewriteCond %{HTTP_HOST} ^www.sushain.com$</p><p>RewriteRule ^contest http://127.0.0.1:12009%{REQUEST_URI} [P,QSA,L]</p><p>DirectoryIndex preload.html index.html</p><p># BEGIN WordPress</em></p><p><em># END WordPress</em><br />

I immediately knew that the URL rewriting module was causing some issue here, but I didn't want to tinker with this since I may want my Ruby app (although dormant for now) to come alive again in future. So, what I did instead was that I changed the .htaccess file in the /blog folder from -

DirectoryIndex index.php

AuthUserFile "/home/sushainp/.htpasswds/public_html/blog/passwd"

to - 

<em>DirectoryIndex index.php AuthUserFile "/home/sushainp/.htpasswds/public_html/blog/passwd" # BEGIN WordPress <ifmodule> RewriteEngine On RewriteBase /blog/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] </ifmodule></em> <em># END WordPress</em>
This overrode the URL rewriting mechanism for /blog level addresses and thus, solved the issue.

By the way, for those of you interested in knowing more about URL-rewriting module, more information is available here.

Cheers !

No comments:

Post a Comment