How to redirect a sub-domain to its sub-directory in the WWW root

I was searching the internet to find a solution to my WordPress problem. My blog (blgr.info) needed to be hosted on the root directory (www.blgr.info) per AdBrite publisher requirement. While I can just edit the WordPress settings and use Search and Replace plugin to update the links on my articles, I’ll be having a problem about the existing search engine links.

I found several tutorials but they just either send me to the root domain, or give me HTTP 500 errors.

I found a solution at StackOverflow, and I’ll post below my WordPress .htaccess modification:

# BEGIN WordPress
RewriteCond %{HTTP_HOST} !^blgr.info$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).blgr.info$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^/?(.*)$ http://www.blgr.info/$1 [R=301,QSA,L,NE]


RewriteEngine On
RewriteBase /blog/
RewriteRule ^index.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

# END WordPress

Now, the last thing to do is update my Google Webmasters and Google Analytics…

Leave a Reply

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