Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Following is the content of .htaccess file

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  Options +Indexes
  RewriteEngine On
  RewriteBase /
  RewriteCond %{HTTP_HOST} ^(.+)\.example\.org$ [NC]
  RewriteRule ^(.*)$ [L]

My purpose is to map all subdomain to folders. For example if is opened it should show the content of But the URL should not change.

But whenever I open the URL is automatically getting changed. How can I prevent it?

share|improve this question

migrated from Aug 10 '11 at 6:09

This question came from our site for professional and enthusiast programmers.

2 Answers 2

You can't use absolute URLs

RewriteCond %{HTTP_HOST} ^(.+)\.example\.org$ [NC]
RewriteRule ^(.*)$ /%1 [L]
share|improve this answer
This does assume that both the subdomain and the main domain point to the same place on the filesystem. – w3d Oct 31 at 23:17
AFAIK there is a difference between $1 and %1. First comes from regexp in RewriteRule, second - in RewriteCond. – Jacek Kaniuk Nov 2 at 14:47
Yes, I'm not disputing that - your directives look correct. However, as stated above, this will only work if the subdomain and the main domain point to the same place (ie. to the main domain's document root) - which they often do not. So, (the equivalent filesystem path) must be accessible. Just saying. – w3d Nov 2 at 15:08
It's not the same place, but subfolder ;), but yes - you have a point here – Jacek Kaniuk Nov 2 at 15:17

It sounds like you want a reverse proxy. Fortunately, there's a flag to do this.

So you need to enable mod_proxy and add P to the RewriteRule flags.

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.