logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Need to redirect of all the non-www to the www
Author
SMc



Joined: 12 Feb 2006
Posts: 17
Location: Chelmsford, UK

PostPosted: Wed 05 Jul '06 22:26    Post subject: Need to redirect of all the non-www to the www Reply with quote

Hi,

I need to redirect all non www files to www files e.g.

http://giftofsound.co.uk -> http://www.giftofsound.co.uk

I am running Apache 2.2 on Windows 2000 Server

Is it possible to use mod_rewrite ?

I have tried the following without success......

.
LoadModule rewrite_module modules/mod_rewrite.so
.
.
<IfModule rewrite_module>
Options +FollowSymLinks
RewriteEngine on
RewriteLog logs/rewrite.log
RewriteLogLevel 9
#
# If requested domain is NOT the canonical domain
#
RewriteCond %{HTTP_HOST} !^www\.giftofsound\.co.uk
#
# And if request Host header is NOT blank (HTTP/1.0 requests don't
send this header and can't be redirected based on it)
#
RewriteCond %{HTTP_HOST} !^$
#
# Redirect to same page in canonical domain
#
RewriteRule ^/(.*) http://www.giftofsound.co.uk/$1 [R=301,L]
</IfModule>

I should say that mod_rewrite.so exists in Apache2/modules/mod_rewrite.so.


Any help or advice appreciated !


Regards,

SMc
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3092
Location: Hilversum, NL, EU

PostPosted: Wed 05 Jul '06 22:41    Post subject: Reply with quote

Not sure what you want, but with vhosts you can use ServerAlias:


<VirtualHost *>
ServerName www.apachelounge.com
ServerAlias apachelounge.com
DocumentRoot f:/web/al
</VirtualHost>
Back to top
SMc



Joined: 12 Feb 2006
Posts: 17
Location: Chelmsford, UK

PostPosted: Thu 06 Jul '06 1:38    Post subject: Reply with quote

The Problem is what is known as the canonical domain issue....

in other words, if you allow both of the options below to resolve,

http://www.giftofsound.co.uk
http://giftofsound.co.uk

...then your search engine page rank will be seriously affected because search engines will see that as duplicate page content and demote accordingly.

Therefore it is necessary that when someone types in http://giftofsound.co.uk the server makes a 301 re-direct to http://www.giftofsound.co.uk and your page rank is fine....

I am looking for an easy way to achieve that ReDirect in Apache in Windows....

SMc
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3092
Location: Hilversum, NL, EU

PostPosted: Thu 06 Jul '06 7:29    Post subject: Reply with quote

I am not an Rewrite expert,
you did not escape the dot in .uk.

RewriteCond %{HTTP_HOST} !^www\.giftofsound\.co\.uk


Steffen


Last edited by Steffen on Thu 06 Jul '06 7:47; edited 2 times in total
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3092
Location: Hilversum, NL, EU

PostPosted: Thu 06 Jul '06 7:38    Post subject: Reply with quote

Found this:


RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !=""
RewriteRule ^/(.*) http://www.example.com/$1 [L,R=301]


Steffen
Back to top
SMc



Joined: 12 Feb 2006
Posts: 17
Location: Chelmsford, UK

PostPosted: Thu 06 Jul '06 11:10    Post subject: Reply with quote

Hi Steffen,

...thanks for that spot on the dot !

...I think my problem is that the mod_rewrite is not functioning for me at all....I would expect to see something in the rewite.log but it is always just blank !

Is there a setting or settings in the httpd.conf that I have forgotten ?

Perhaps a way to test it somehow....



Regards,


SMc
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3092
Location: Hilversum, NL, EU

PostPosted: Thu 06 Jul '06 13:04    Post subject: Reply with quote

If using vhosts, place the rewrite code in the Vhost container, or place in the Vhost container: RewriteEngine on and RewriteOptions inherit .

Steffen
Back to top
SMc



Joined: 12 Feb 2006
Posts: 17
Location: Chelmsford, UK

PostPosted: Thu 06 Jul '06 14:00    Post subject: Reply with quote

...Thanks Steffen,

...fantastic advice, it works perfectly now......

...excellent !!........happy days are here again......doobie doo da..
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3092
Location: Hilversum, NL, EU

PostPosted: Thu 06 Jul '06 14:53    Post subject: Reply with quote

You can do something back: make a little How-to/Tip in the "How-to's & Documentation & Tips" forum here. I think it is great Tip to increase Ranking.

Thanks,

Steffen
Back to top
SMc



Joined: 12 Feb 2006
Posts: 17
Location: Chelmsford, UK

PostPosted: Thu 06 Jul '06 15:36    Post subject: Reply with quote

Hi Steffen,

Done !


SMc
Back to top


Reply to topic   Topic: Need to redirect of all the non-www to the www View previous topic :: View next topic
Post new topic   Forum Index -> Apache