Results 1 to 7 of 7

Thread: Removing www from URL

  1. #1
    Registered Hylo's Avatar
    Join Date
    Oct 2005
    Location
    Northern Ireland
    Posts
    74

    Removing www from URL

    I want all of my URLs to redirect the www version to the non "www" version and found this htaccess code to do it:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^mydomain.com$ [NC]
    RewriteRule (.*) http://mydomain.com/$1 [R=301,L]

    I have forums on a forums.mydomain.com subdomain though and it's removing the sub domain when I use this code.

    Is there any way around this with mod_rewrite or will I have to content myself with using mydomain.com/forums instead of the sub domain?

    For every chemical you trade a piece of your soul

  2. #2
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    I'm not a mod_rewrite expect but the problem is that you're looking for a wildcard and changing it.

    Changing your forum URL would be one idea, and I usually recommend not using subdomains anyways unless the subdomain is a physically different server, however you'd lose a lot of incoming links (maybe... how established is it?).

    I imagine you can tweak it to forward correctly, but again, I'm not exactly where where to make the change.

    Also be sure to use Google Webmaster Central to tell Google which version you prefer.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  3. #3
    I'm the oogie boogie man! James's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,566
    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www.mydomain.com$ [NC]
    RewriteRule (.*) http://mydomain.com/$1 [R=301,L]
    Isn't that all you need? You're just trying to take out the www., so *shrugs*

  4. #4
    Is Still Alive! Johnny Gulag's Avatar
    Join Date
    Feb 2006
    Location
    North Texas
    Posts
    242
    I use the following and have never had any trouble, though as Chris says I am no Apache expert.

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

  5. #5
    I'm the oogie boogie man! James's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,566
    what are the backslashes infront of the dots for?

  6. #6
    Is Still Alive! Johnny Gulag's Avatar
    Join Date
    Feb 2006
    Location
    North Texas
    Posts
    242
    Quote Originally Posted by James
    what are the backslashes infront of the dots for?
    No idea.

  7. #7
    Site Contributor stymiee's Avatar
    Join Date
    Dec 2004
    Location
    Between the Pipes
    Posts
    275
    They escape the period so it literally means "period". Otherwise the period means "any character" in regular expressions.
    John Conde :: brainyminds
    Merchant Account Services -- Merchant Services Resources
    IT'S HERE: Integrate the Authorize.net Payment Gateway with PHP
    Everything you need to integrate Authorize.net into your website with PHP. Includes an explanation of how transactions work, validating credit cards, and the source code for free.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •