"Chris" <weeged.RemoveThis@gmail.com> schreef in bericht
news:4d39f7c0.0502280145.b2f22c2@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
<font color=purple> > mysite.com or <a style='text-decoration: underline;' href="http://www.mysite.com</font" target="_blank">www.mysite.com</font</a>>
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 (.*) <a style='text-decoration: underline;' href="http://www.%2$1?d=1" target="_blank">http://www.%2$1?d=1</a> [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 <a style='text-decoration: underline;' href="http://www.misite.com" target="_blank">www.misite.com</a> or <a style='text-decoration: underline;' href="http://www.myside.com" target="_blank">www.myside.com</a> 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<!-- ~MESSAGE_AFTER~ -->
>> Stay informed about: Redirect for missing 'www' in URL