Mod_rewrite Question

Hi there,

First of all, I should say I am a newbie on whole hosting stuff.

So, here is the question.

I’d like to set something like after you type and press Enter on IE, then it can be redirected to, so I did my homework on Google, and I created a .htaccess file include the following sentences,

RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]$
RewriteRule ^(. ) %{HTTP_HOST}$1 [C]
RewriteRule ^([^.] )*) /$1$2

I put the file in the root of my web address, however, it doesn’t works as when I type, they all go to

Anyone can help me to sort this out? Since I think people perfer than


It seems to me that you are trying to make this a lot harder than it is. Thanks to Dreamhost’s allowing free subdomains, the easiest way for you to have people to go to is to just set up “aaa” as a subdomain of

This can seem a little confusing, as some other web hosts use the subdirectory of the webspace as a subdomain, but on Dreamhost, can have its very own webspace.

While the end result is the same, it is actually better for your guests, and the server, as no additional re-write requests need to be handled by the server.

If you set up aaa as a subdomain of, you will have both and as directories within your machine user space. Another advantage this provides is that each can have their own associated email addresses, system software configuration, .htaccess files/rules, etc.

You can still link between the sites, even though you can manage them as two different sites. All in all, it’s just a much easier and more efficient way to do this than using a subdirectory and manipulating urls via Apache re-write rules and .htaccess.


Hi rlparker,

Thanks for your advise, I think it is a very good point that has its own space on DH. But on this practical case, i think if I do your way, then I have to take more works such as rebuild the database, redirect the sitemap and sth like that. Therefore, maybe for my next site, I will using your way but for this time, I still need someone who can help me with the mod_rewirte codes.

Regards, Yishi


I understand. Here is another shortuct that is available on Dreamhost that will allow you to leave your content structure as but allow that sub-directory to function as the subdomain without htaccess/re-write rules:

  1. From the Control Panel, create a New Domain / sub-domain screen, create a new Fully Hosted sub-domain named

  2. Select the version of PHP you want, whether or not you want to use mod_security (extra web security), fastcgi, etc and select the user to run cgi as (I suggest you use the same user as

  3. In the “Web Directory” field, instead of the “default” value that is there (which should be /home/username/, enter /home/username/, and submit the form. Be careful not to add the ending “/” as it is automatically added as indicated). Submit the form.

Once DNS has propagated, all your content in /home/username/ will be reachable by either or

This way you get the best of both worlds with your exisiting directory structure, and avoid Apache re-write altogether. :wink:


I don’t see anyway for an .htaccess file place in will ever get a chance to act on a request for

Unless there is a DNS entry for, how are you even getting that to redirect to

You could create a subdomain called, and redirect it to from the control panel, but I don’t see how to make what you want to do work, as should fail before the .htaccess file in gets a chance to re-write any rules (or maybe I am just exceptionally slow tonight :wink: ).

re-write rules are a little like “voodoo magic” to me, and are not my area of specialty. Maybe one of the re-write experts on here can help.



What a great idea, just did what you say, will let you know the result later.


Hello, it works great, thank you for your advise. Regards, Yishi

That’s great news. I’m really glad it worked for you. :slight_smile: