Changing "host.example.com" to "www.example.c

Using a single web hosting account to host multiple sites

Changing "host.example.com" to "www.example.c

Postby BenBaugh » Thu Jan 25, 2007 12:43 pm

This is almost embarrassingly simple, I'm sure, but I'm such a mod_rewrite novice, that even something this basic is stumping me.

Our server would resolve both of these addresses to the same resource:

Code: Select all
http://host.exapmle.example2.com

http://www.example.example2.com


Over the years, both of these URL's have been used interchangeably, and so there are lots of hard coded links to both scattered all over the place.

But now, as part of a overall site redesign, we want to get all our url's consistent. Which brings me to Mod_Rewrite.

I thought it would be as simple as using a RewriteRule to to take any address with "host" in it, capture everything that follows it, and then append it all onto "www".

The best I can figure, it would be something like this:

Code: Select all
RewriteRule ^host\.(.*)$ www$1 [L]


But that doesn't do the job, so it obviously isn't.

If I can get over this niggling little issue, then I'll have time to play with mod_rewrite and see what I can really do... but for now, I just need some help with this little thing.

Thanks,

-B
BenBaugh
 
Posts: 4
Joined: Wed Jan 24, 2007 8:11 am

Postby richardk » Fri Jan 26, 2007 11:28 am

The part matched by RewriteRules is between the currect dircetory (where the .htaccess file is) and the ?.

In a .htaccess file in your document root:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^host\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby BenBaugh » Fri Jan 26, 2007 11:39 am

Oh rock- that seems to do the trick!

Mod_Rewrite is just too cool.

Enormous and vast thanks!

-B
BenBaugh
 
Posts: 4
Joined: Wed Jan 24, 2007 8:11 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 20 guests

cron