No "www" rewrite issue

Discussion in 'Apache' started by xxkylexx, Mar 19, 2007.

Thread Status:
Not open for further replies.
  1. #1
    Hey guys,
    I'm trying to use a rewrite rule to force no www. on my site's URLs.

    I've used the following, but it's conflicting with my previous rewrite rules.

    # -Manipulate URLs-
    
    RewriteEngine on
    RewriteRule ^index/?$ index.php [L]
    RewriteRule ^hosting/?$ hosting.php [L]
    RewriteRule ^support/?$ support.php [L]
    RewriteRule ^about_us/?$ aboutus.php [L]
    RewriteRule ^testimonials/?$ testimonials.php [L]
    RewriteRule ^terms/?$ terms.php [L]
    RewriteRule ^privacy/?$ privacy.php [L]
    RewriteRule ^site_map/?$ sitemap.php [L]
    
    # -Force non-www URLs-
    
    RewriteCond %{HTTP_HOST} ^www\.websolvents\.com$ [NC]
    RewriteRule ^(.*)$ http://websolvents.com/$1 [R=301,L]
    Code (markup):
    If I enter http://www.websolvents.com/hosting/ , it will rewrite to http://websolvents.com/hosting.php , which is incorrect. I want it to rewrite to http://websolvents.com/hosting/ .


    Any ideas?


    Thanks much!

    Kyle
     
    xxkylexx, Mar 19, 2007 IP
  2. tnd

    tnd Well-Known Member

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #2
    If you want to redirect to non-www only and no other redirect then you can mark out all these line

    
    #RewriteRule ^index/?$ index.php [L]
    #RewriteRule ^hosting/?$ hosting.php [L]
    #RewriteRule ^support/?$ support.php [L]
    #RewriteRule ^about_us/?$ aboutus.php [L]
    #RewriteRule ^testimonials/?$ testimonials.php [L]
    #RewriteRule ^terms/?$ terms.php [L]
    #RewriteRule ^privacy/?$ privacy.php [L]
    #RewriteRule ^site_map/?$ sitemap.php [L]
    
    Code (markup):
     
    tnd, Mar 19, 2007 IP
  3. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #3
    rodney88, Mar 20, 2007 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    # -Manipulate URLs-
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^index/$ index.php [L]
    RewriteRule ^hosting/$ hosting.php [L]
    RewriteRule ^support/$ support.php [L]
    RewriteRule ^about_us/$ aboutus.php [L]
    RewriteRule ^testimonials/$ testimonials.php [L]
    RewriteRule ^terms/$ terms.php [L]
    RewriteRule ^privacy/$ privacy.php [L]
    RewriteRule ^site_map/$ sitemap.php [L]

    # -Force non-www URLs-
    RewriteCond %{HTTP_HOST} ^www\.websolvents\.com$ [NC]
    RewriteRule ^(.*)$ http://websolvents.com/$1 [R=301,L]


    and you can try it with the -Force non-www URLs- part first.
     
    Nintendo, Mar 20, 2007 IP
  5. xxkylexx

    xxkylexx Peon

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5

    That did it. Thanks much.
     
    xxkylexx, Mar 20, 2007 IP
Thread Status:
Not open for further replies.