1

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

http://wiki.dreamhost.com/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.

user282145
  • 11
  • 4

1 Answers1

0

Some of this code..

http://wiki.dreamhost.com/Transparently_redirect_your_root_directory_to_a_subdirectory

..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.

user282145
  • 11
  • 4