+ Reply to Thread
Results 1 to 5 of 5

Thread: Redirect www.mydomain.com to mydomain.com

  1. #1
    scrame is offline x10Hosting Member scrame is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    6

    Redirect www.mydomain.com to mydomain.com

    So, I've been looking all over for a way to do this, but I want users to only use the non-www version of my website. Most of what I've seen says to use the htaccess file to set sort of a global redirect to remove the www.

    Now, I've been messing with the htaccess and everything I do results in a redirect error (it looks like it's a neverending loop issue).

    I guess the main question I have is whether or not htaccess is the way to do this. If so, what code should I be using? And if not, what else should I be looking into?

    Thanks in advance for any help, I've been playing with this all day and having absolutely no luck... seems like a pretty simple problem, but I can't find an answer... Thanks!

  2. #2
    Zubair's Avatar
    Zubair is offline x10 Super Spammer Zubair has a reputation beyond reputeZubair has a reputation beyond reputeZubair has a reputation beyond repute
    Join Date
    Jul 2009
    Location
    Pakistan
    Posts
    8,747

    Re: Redirect www.mydomain.com to mydomain.com

    Add this in your .htaccess file
    Code:
    Options +FollowSymlinks
    RewriteEngine on
    
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^yourdomain.com$
    RewriteRule ^(.*)   http://www.%{HTTP_HOST}/$1  [QSA,L,R=301]
    Last edited by Zubair; 02-01-2010 at 12:40 AM.
    Zubair Barkat | Level 2 Tech
    █ 888-X10-9668 - zubair[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004

  3. #3
    scrame is offline x10Hosting Member scrame is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    6

    Re: Redirect www.mydomain.com to mydomain.com

    Thanks for responding, I hadn't been able to get anything else to work, but this one is getting somewhere.

    One question, should I be replacing 'yourdomain.com' with my actual domain? The only reason that I ask is that when I leave it as yourdomain.com it works but when I change it to xyz.com, it doesn't. Does that make any sense?

    The other question is that I would prefer that people who do enter the www.xyz.com be taken to zyz.com. Is there an easy way to do this as well?
    Last edited by scrame; 02-01-2010 at 01:32 AM.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Redirect www.mydomain.com to mydomain.com

    All over? Are you sure? This is covered in Apache's "URL Rewriting Guide".
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: Redirect www.mydomain.com to mydomain.com

    This should work (Boss turned it around and added some useless code to it) :
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www.yoursite.com$
    RewriteRule ^(.*)$ http://yoursite.com/$1 [R=permanent, L]
    And yes, you can replace "yoursite.com" with your actual domain.

    Edit: about your www.xyz.com to zyz.com, are you sure that's not a typo? Either way, if you replace the "www.yoursite.com" with "www.xyz.com" and the second "yoursite.com" to "zyz.com" it should work.
    Last edited by marshian; 02-01-2010 at 06:07 AM.
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

+ Reply to Thread

Similar Threads

  1. Case insensitive redirect
    By lydia09 in forum Programming Help
    Replies: 2
    Last Post: 01-31-2010, 08:58 AM
  2. Redirect
    By liguehs in forum Free Hosting
    Replies: 3
    Last Post: 07-23-2009, 09:12 AM
  3. sort of redirect help
    By galaxyAbstractor in forum Programming Help
    Replies: 4
    Last Post: 06-14-2008, 06:08 AM
  4. Redirect
    By BlueIce in forum Free Hosting
    Replies: 3
    Last Post: 10-21-2007, 08:06 AM
  5. Cpanel Redirect problem
    By BigEmmaFanz in forum Free Hosting
    Replies: 5
    Last Post: 12-10-2005, 04:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers