A bit more detail:

lets say I have the following domains that I do not have DNS control over (they are just public websites)

www.example.com sub.example.com

If there is a way, how could I get my computer to automatically forward me to sub.example.com when I accidentally forget and type www.example.com?

I was thinking that I might be able to use the hosts file and Apache, and do a redirect there, but does anyone have any other suggestions?

My example:

Hosts file: www.example.com

Apache configuration (or .htaccess file):

RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^$ http://sub.example.com/? [L,R=301]

Would this work, if so, is this the best way to do this, or is there a better way?

1 Answer 1

  1. Add an entry for www.example.com to your hosts file

  2. Configure a local Apache VirtualHost with ServerName www.example.com

  3. Put this in the VirtualHost: Redirect permanent / http://sub.example.com

An alternative way would be to use something like the GreaseMonkey Plugin (or equivalent) in your browser and have it do the redirect in a user script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .