The following DreamHost wiki explains how to transparently redirect your root directory to a subdirectory..


The recommended code is..

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/blog/
RewriteCond %{HTTP_HOST} ^(www\.)?domain\. 
RewriteRule ^(.*)$ /blog/$1 [L]

However, the recommended code only works on the www subdomain and restricts access to all root directories other than blog.

Here are my specific questions..

  1. How can I modify the code so it works with any subdomain (any.domain.com) and also works with no subdomain (domain.com)?

  2. How can I make domain.com redirect to domain.com/blog while still allowing access to domain.com/any-other-directory ?

UPDATE: This question has been incorrectly marked as duplicate. The suggested post does not answer this specific implementation question about this specific hosting provider. I don't have the reputation points yet to add this to the suggested post, so if someone adds my question to the suggested post then I'll remove this question. Thanks.

marked as duplicate by MDMoore313, dawud, Scott Pack, 84104, Katherine Villyard Apr 18 '15 at 3:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Some of this code..


..and some of this code..

How to redirect root and only root via htaccess?

..makes this solution..

RewriteEngine on
RewriteCond %{HTTP_HOST} domain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /blog/$1 [L]

FYI, if you are using this code in the root .htaccess file of your own website, you will need to change "domain" to your specific TLD (Top Level Domain) and "blog" to whatever subdirectory you want the root to transparently redirect into.

Not the answer you're looking for? Browse other questions tagged or ask your own question.