Redirect "domain.com" to "www.domain.com"

Discussion in 'Install/Configuration' started by Flornet, Jul 21, 2007.

  1. Flornet

    Flornet New Member

    In apache, I used Redirect Permanent in a vhost for "domain.com".

    In litespeed, I've set up a listener on www.domain.com. WHY does it also work when I connect to domain.com ???

    I just want domain.com to redirect to www.domain.com ...seems simple :)

    Any help apreciated,

    Florent J.
  2. mistwang

    mistwang LiteSpeed Staff

    A simple redirect rule should do the trick.
    LiteSpeed strip the leading "www." by default.
  3. Flornet

    Flornet New Member

  4. PSS

    PSS Member

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

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

    # And for a site running on port 80
    RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC]
    RewriteCond %{HTTP_HOST} !^$
    RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R]

    --

    And I use this to redirect www to non-www (the way I like it):

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

    I think rewrites like that should include 301 in order to get robots note the end location only.
    Last edited: Jul 24, 2007
  5. Flornet

    Flornet New Member

    Works great. Many thanks.

Share This Page