Forum Moderators: phranque

Message Too Old, No Replies

Remove www from domain name

         

inerte

8:28 pm on Nov 19, 2006 (gmt 0)

10+ Year Member



Hi all!

I have a http://www.example.com/ domain which I want to redirect/rewrite to http://example.com/. Right now, loading www.example.com or example.com works, I guess because of the ServerName/ServerAlias.

Here's what I tried, and it doesn't work (the commented lines). First with rewrite then with redirect.

<VirtualHost *>
ServerName www.example.com
ServerAlias example.com
# Rewrite
# RewriteEngine On
# RewriteRule ^(.*) http://example.com.br$1 [R=301,L,NE]
# Redirect
# Redirect permanent / http://example.com
</VirtualHost>

Anyone knows the right syntax?

Many thanks!

jdMorgan

2:13 pm on Nov 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you wish to include the redirect inside the same VirtualHost container, then you'll need to qualify the redirect so that it only happens when the requested domain is the "wrong" one:

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

The alternative is to delete the ServerAlias from the current vhost container, and then add a second vhost container for the "www" domain which contains only an unconditional redirect to the canonical non-www domain.

Jim

inerte

4:51 pm on Nov 20, 2006 (gmt 0)

10+ Year Member



Thank you jdMorgan!