how do i redirect my domian to www.

Discussion in 'PHP' started by Reputable, Jun 20, 2012.

  1. #1
    how do i redirect my domain to www. so when someone types mydomain.com i want it to redirect to www.mydomaincom


    also my sites script is working of my server name i want it to work on my real domain name
     
    Reputable, Jun 20, 2012 IP
  2. BunnyB

    BunnyB Peon

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you've installed Google Webmaster Tools, you can go in and set your preferred domain. Then Google will redirect all queries to your preferred version.
     
    BunnyB, Jun 20, 2012 IP
  3. accesstimes

    accesstimes Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    something like this in PHP


    header("Location: http://www.whatever.com/{$_SERVER['REQUEST_URI']}");


    I would use mod rewrite over PHP though
     
    accesstimes, Jun 20, 2012 IP
  4. Chuckun

    Chuckun Well-Known Member

    Messages:
    1,161
    Likes Received:
    60
    Best Answers:
    2
    Trophy Points:
    150
    #4
    You guys are crazy xD

    Just use this in .htaccess

    RewriteCond %{HTTP_HOST} ^YOURDOMAIN.COM$
    RewriteRule ^(.*)$ "http\:\/\/www\.yourdomain\.com\/$1" [R=301,L]
    Code (markup):
     
    Chuckun, Jun 20, 2012 IP
  5. freelanceinphp

    freelanceinphp Member

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #5
    use htaccess is a perfect option. Use Chuckun code and change your website name instead of YOURDOMAIN.com
     
    freelanceinphp, Jun 20, 2012 IP
  6. Traditione

    Traditione Well-Known Member

    Messages:
    731
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    120
    #6
    lol they just wanted to do it the more complicated way. I guess some people like making 3 left turns to go right.

    If you have cpanel, you can just go to the redirects section too.
     
    Traditione, Jun 20, 2012 IP