Webmasters Stack Exchange is a question and answer site for pro webmasters. 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

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 ^(.*)$ http://example.org/%1 [L]

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

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

share|improve this question

migrated from stackoverflow.com Aug 10 '11 at 6:09

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

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. – w3dk Oct 31 '15 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 '15 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, a1.example.com/a1 (the equivalent filesystem path) must be accessible. Just saying. – w3dk Nov 2 '15 at 15:08
It's not the same place, but subfolder ;), but yes - you have a point here – Jacek Kaniuk Nov 2 '15 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.