how to automatically add www prefix?

Discussion in 'Apache' started by dinodonk, Dec 23, 2005.

  1. #1
    how to redirect all mydomain.com to www.mydomain.com

    i have try
    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
    RewriteRule ^(/.*) http://www.mydomain.com/$1 [L,R=301]
    Code (markup):
    it's only work for domain.com/something , not work for domain.com/forum/something

    TIA
     
    dinodonk, Dec 23, 2005 IP
  2. The Big Deal

    The Big Deal Peon

    Messages:
    212
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
     
    The Big Deal, Dec 23, 2005 IP
  3. Blue

    Blue Peon

    Messages:
    65
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This is what I use:

    
    # Redirect to WWW
    
    rewriteCond %{HTTP_HOST} !^www\.mysite\.com
    rewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
    Code (markup):
     
    Blue, Dec 23, 2005 IP
  4. dinodonk

    dinodonk Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks to all replies. i have tried your suggestion but still no luck

    it works for example.com/forum ( no trailing slash )
    but that doesn't work too for
    example.com/forum/showthread.php
    example.com/forum/

    maybe need something more on rewriteRule condition?

    Regards
     
    dinodonk, Dec 23, 2005 IP
  5. cpucandy

    cpucandy Peon

    Messages:
    489
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Give this a try:

    RewriteEngine On
    RewriteCond %(HTTP_HOST) !^www.mydomain.com$ [NC]
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R,L]
     
    cpucandy, Dec 23, 2005 IP
  6. dinodonk

    dinodonk Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    @Cpucandy : thanks but still not working for mydomain.com/forum/
     
    dinodonk, Dec 25, 2005 IP