Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to keep my blog in subfolder domain_com/htdocs/blog and access it using I can obtain it using apache's mod_rewrite:

RewriteEngine On
RewriteBase /

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

But I also want to redirect hxxp:// to hxxp:// (simply because I want to hide it from users). Simple redirection like:

RewriteCond %{HTTP_HOST} ^wojtyniak\.com$
RewriteRule %{REQUEST_URI} ^/foo
RewriteRule ^(.*)$  [L,R=301]

causes redirection loop. Is there any way to make such a redirection without loop? Big thanks!

PS. Sorry for those hxxp thing, but serverfault thinks these are link and doesn't allow me to post more than one.

share|improve this question
up vote 1 down vote accepted

The most ideal solution would be to put this on a virtual-host, with the blog files hosted somewhere outside of your htdocs directory.

I'm going to assume that you won't have access to make these necessary changes, but in case you do, here's the documentation for it.

share|improve this answer
Unfortunately I can't create new vhost:( – radious Dec 18 '09 at 17:25

Yes, I know. Noone will need this anymore here, after 2 years. But maybe someone who is redirected here by Google.

# Rewrite <subdomain><path> to<subdomain>/<path>
# Skip rewrite if no hostname or if subdomain is www
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain (%1), and first path element (%3), discard port number if present (%2)
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example\.com(:80)?<>/([^/]*) [NC]
# Rewrite only when subdomain not equal to first path element (prevents mod_rewrite recursion)
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
# Rewrite to /subdomain/path
RewriteRule ^(.*) /%1/$1 [L]

I found that here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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