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

How can I create a rewrite rule which rewrites the browser url such that requests to is always shown as

No redirection of the page is needed.

share|improve this question

closed as not constructive by HopelessN00b, Brent Pabst, rnxrx, Ward, Magellan Oct 10 '12 at 5:06

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

Please use the search function next time. There are literally dozens of questions on here where you'd find your answer. – HopelessN00b Oct 8 '12 at 1:33

If I understand you correctly, what you want is this:

  • The client types in in his browser
  • The text in the address field of the browser changes to
  • The contents shown are still the same

If so, you must have a redirect. That's the way to do the change in the address bar. You can't just edit the browser address bar on somebody else's computer.

So the first thing you do is the redirect as posted by LogicWreck. Then you add a VirtualHost entry either to your httpd.conf or your .htaccess file, containing something like

<VirtualHost *:80>
     DocumentRoot /path/to/webfiles/sub

and probably some more directives; have a look at You could also add another rewrite rule to find the files under the correct directory, but generally speaking a normal VirtualHOst would be better.

If you want to use a rewrite rule instead of VirtualHost, you would do something like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^($
RewriteRule /(.*) /path/to/webfiles/sub/$1

But I would recommend the VirtualHost route; that's the normal way of doing something like this.

share|improve this answer
Thanks for the answer but. But I need it on an other way. The user types and a redirect send the user to but in the browser shouldn't change the url. They should see always on every time they are on the page. – Karl Pilz Sep 10 '12 at 11:03
In that case, using a virtual host the way I described is the most common way. But I'll add code for doing it with a rewrite instead. – Jenny D Sep 10 '12 at 12:10
Would be really helpful. Thanks a lot. – Karl Pilz Sep 10 '12 at 12:14

You just need to create a .htaccess in the /sub directory of with the next contents:

RewriteEngine on
RewriteRule ^(.*)$$1 [R=301]
share|improve this answer
Hi, thanks for your answer but it doesn't work. – Karl Pilz Sep 10 '12 at 9:48
I have a subdomain which is redirected to a subfolder. The browser tells that it's not possible why he redirects always. I only need to rewrite the browser url. No redirect. – Karl Pilz Sep 10 '12 at 9:50

@Jenny D is correct that you need a virtual host answering to before you start this, and also that the browser does need to be redirected - there's no other way to change what appears in the browser's address bar.

The redirect you need, however, does not require mod_rewrite. Visit the "When Not to Use Rewrite" wiki page and you'll find the much lighter and simpler method:

Redirect sub/
share|improve this answer

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