Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Redirect for missing 'www' in URL

20 views
Skip to first unread message

Chris

unread,
Feb 28, 2005, 4:45:07 AM2/28/05
to
Hi, is there anyway I can redirect a user who has forgotten to enter
the www part at the beginning of a URL?

i.e I want to direct a user to the same content whether they enter
mysite.com or www.mysite.com

I'm using name-based virtual hosting and any help would be
appreciated.

Regards
Chris

Message has been deleted

HansH

unread,
Feb 28, 2005, 7:39:28 AM2/28/05
to
"Chris" <wee...@gmail.com> schreef in bericht
news:4d39f7c0.0502...@posting.google.com...

> Hi, is there anyway I can redirect a user who has forgotten to enter
> the www part at the beginning of a URL?
>
> i.e I want to direct a user to the same content whether they enter
> mysite.com or www.mysite.com
First things first, both names has to resolve over DNS to the same IP.

> I'm using name-based virtual hosting and any help would be
> appreciated.

I'm using a rewrite in the _default_ virtual host:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www)\.
RewriteCond %{HTTP_HOST} ^([^\.]+\.)?([^\.]+\.[^\.]+)$
RewriteRule (.*) http://www.%2$1?d=1 [R=301,QSA,L]

The 'd=1' is only a reference logged with the redirected request by the
proper vhost.
( 'Using another Rewrite at the same vhost to take care of spelling errors
... like www.misite.com or www.myside.com and adds 'd=2' as marker )

For the default vhost you may want to append the host name to the log
LogFormat "%h %l %u ....... \"%{host}i\"" combined-host

HansH


0 new messages