The Community Forums

Interact with an entire community of cPanel & WHM users.
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

redirect http://www.site.com to http://site.com

Discussion in 'General Discussion' started by Chew, Jun 5, 2004.

  1. Chew

    Chew Well-Known Member

    Joined:
    Dec 31, 2003
    Messages:
    96
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Maryland
    I know I saw a php script to do this somewhere, however my brain is fried at 5:30am and I have searched everywhere.

    I use cookies that require my visitors to use http://site.com however a large majority of the internet population uses www.site.com still.

    How do I go about redirecting them to http://site.com if they came in from http://www.site.com?

    Thanks in advance!
    Chew
     
  2. jameso

    jameso Registered

    Joined:
    Sep 25, 2003
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Use the following in a php script:

    PHP:
    <?php 

    $server 
    getenv("HTTP_HOST"); 

    if (
    ereg("^www."$server)) { 
        
    // Assume www. has been entered 
        
    Header ("Location: http://".$server."/"); 
        Exit; 
         


    ?> 
    That should do what you're trying to do.

    Cheers,

    James
     
  3. jameso

    jameso Registered

    Joined:
    Sep 25, 2003
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    You can also use mod_rewrite in your .htaccess file. Put it inside your public_html directory in order for the changes to effect all files/directories.

    The code below is for doing the opposite to what you wish to do (ie going from no www to a url with www). I'm not a mod_rewrite expert so I'm not sure how to reverse the effect of it:
    Code:
    RewriteEngine On
    Options +FollowSymlinks
    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
    Replace domain and .com as necessary.

    James
     
  4. Chew

    Chew Well-Known Member

    Joined:
    Dec 31, 2003
    Messages:
    96
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Maryland
    Thanks tons to the both of you.

    Gonna have to figure out which one works best for my usage :)

    Chew
     
  5. jameso

    jameso Registered

    Joined:
    Sep 25, 2003
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    I think if you can work out how to reverse the mod_rewrite option, it will be better because I think it will forward http://www.site.com/filename to http://site.com/filename.

    I'm pretty sure the php method will only forward it to the main page on your site.

    James
     
  6. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
  7. ryno267

    ryno267 Well-Known Member

    Joined:
    Mar 3, 2004
    Messages:
    212
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Chandler, AZ
    cPanel Access Level:
    Root Administrator
    Just found this and thought i'd have to butt in and ressurrect this puppy...


    Redirects are ok but you should really be doing a 301 Redirect for SEM sake, and thus google will love you as will yahoo, etc.

    In php:
    Code:
    <?php
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: http://new-url.com" );
    ?> 
    
     
  8. brianoz

    brianoz Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,146
    Likes Received:
    6
    Trophy Points:
    38
    Location:
    Melbourne, Australia
    cPanel Access Level:
    Root Administrator
    Chew,

    This doesn't make sense, because as I understand it cookies registered as being from site.com will also get sent to www.site.com and also to anything.site.com. Have you checked to see whether your cookies are getting there anyway?
     
Loading...

Share This Page