.htaccess help - non-www to www

Discussion in 'Apache' started by Wyla, Dec 24, 2008.

  1. #1
    Need some help with .htaccess. My current code is:

    RewriteEngine On
    RewriteCond %{HTTP_HOST}!^(www\.¦$) [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ([^/\.]+)/$ show.php?a=$1
    RewriteCond %{HTTP_HOST} ^wmtoolbox\.com
    RewriteRule ^(.*)$ http://www.wmtoolbox.com/$1 [R=301,L]
    RewriteBase /
    Code (markup):
    What is does:
    http://wmtoolbox.com >> http://www.wmtoolbox.com
    http://wmtoolbox.com/free/ >> http://www.wmtoolbox.com/show.php/?a=free
    Code (markup):
    What I need is:
    http://wmtoolbox.com/free/ >> http://www.wmtoolbox.com/free/
    Code (markup):
    Basically, change the non-www into the www counterpart. With my code, it gets rid of the url mask and shows the ugly show.php/?a=keyword
    Any ideas?
     
    Wyla, Dec 24, 2008 IP
  2. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #2
    on my site i do a site.com to www.site.com using below simple lines

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.site\.com [NC]
    RewriteRule ^(.*) http://www.site.com/$1 [L,R=301]
    </IfModule>

    this then changes ALL / any URL from non-www to www.
     
    hans, Dec 26, 2008 IP
  3. thuankkk

    thuankkk Active Member

    Messages:
    503
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    95
    #3
    Put this .htaccess file at root of your www directory:
    
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
    RewriteCond %{HTTP_HOST} !^$
    RewriteRule ^(.*) http://www.domain.com/$1 [L,R]
    
    Code (markup):
     
    thuankkk, Dec 27, 2008 IP
  4. xcrox

    xcrox Banned

    Messages:
    232
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I have more simpler way :) . Using cPanel

    Just add " * " as a sub domain using cPanel .

    W8 for activation . After it gets activated . any sub domain will be using www.domain.com .

    and catch the domain name using php code .

    
    $domain="domain.com";
    $host=$_SERVER[HTTP_HOST];
    $sub_domain=explode($domain,$host);
    $sub_domain=$sub_domain[0];
    echo $sub_domain;
    
    Code (markup):
    Check Out http://raxor.info . Made on same logic
     
    xcrox, Dec 27, 2008 IP
  5. kulinar

    kulinar Member

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #5
    So called ugly URLs are caused by this part of the
    RewriteRule ([^/\.]+)/$ show.php?a=$1
    Code (markup):
     
    kulinar, Jan 3, 2009 IP
  6. Shafiq Kamal

    Shafiq Kamal Active Member

    Messages:
    646
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    95
    #6
    Easy Way to do is like:
     
    Shafiq Kamal, Jan 3, 2009 IP