0

Possible Duplicate:
Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?

I would like to redirect my web site this way:

http://www.mywebsite.com --> http://mywebsite.com

how can I achieve it in apahce on centos linux?

Elad
  • 1
  • 1

4 Answers4

2

That type of redirect is probably better done with DNS. Make www.mywebsite.com a CNAME entry for mywebsite.com and put an A record in the mywebsite.com entry.

Keith
  • 331
  • 1
  • 6
1

mod_rewrite is capable of doing it, as well as using a ServerAlias directive if you use vhosts.

richo
  • 938
  • 1
  • 7
  • 16
0

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

Canonical Hostnames

Description: The goal of this rule is to force the use of a particular hostname, in preference to other hostnames which may be used to reach the same site. For example, if you wish to force the use of www.example.com instead of example.com, you might use a variant of the following recipe. Solution:

# For sites running on a port other than 80
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://www.example.com:%{SERVER_PORT}/$1 [L,R]

# And for a site running on port 80
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.example.com/$1 [L,R]
dmourati
  • 24,720
  • 2
  • 40
  • 69
0

You could do an htaccess redirect.

MaQleod
  • 503
  • 2
  • 5
  • 17