1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

DNS configuration

Discussion in 'Plesk 11.x for Linux' started by foulquesd, Oct 22, 2012.

  1. foulquesd

    foulquesd New Pleskian

    10
    35%
    Joined:
    Oct 22, 2012
    Messages:
    5
    Likes Received:
    0
    Hi there,

    I got a problem with my DNS configuration, not a big one as my website works. But i'd like to redirect the normal url of my website (that's to say mydomain.com) to the one with www (www.mydomain.com). Unfortunately my knowledge in DNS and server administration is not enough to do that.
    So if you have any idea how i could do that, i would be pleased to hear (or read in this case) it.

    Thank you for your time.
     
  2. ThomasWales

    ThomasWales New Pleskian

    13
    35%
    Joined:
    Oct 7, 2011
    Messages:
    10
    Likes Received:
    0
    Hello foolguesd,

    I would recommend you to do a .htaccess file with the following rewrite rule

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
     
  3. foulquesd

    foulquesd New Pleskian

    10
    35%
    Joined:
    Oct 22, 2012
    Messages:
    5
    Likes Received:
    0
    Thank you Thomas.
    At first I doubted the solution cause I use kind of the same thing to do url rewriting and it doesn't really redirect the user. But it works and that prooves that i got a lot to learn in that domain.
     
  4. abdi

    abdi Platinum Pleskian

    31
    18%
    Joined:
    May 14, 2006
    Messages:
    2,913
    Likes Received:
    60
    and if your website is written in php then this small code can also do the same:

    Code:
    if (!preg_match('/www\..*?/', $_SERVER['HTTP_HOST'])) { 
        if(!EMPTY($_SERVER['QUERY_STRING'])) 
            header("location: http://www." . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']); 
        else 
                header("location: http://www." . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); 
    }  
    
    You just put it ontop of your index file or so ...
     
  5. ThomasWales

    ThomasWales New Pleskian

    13
    35%
    Joined:
    Oct 7, 2011
    Messages:
    10
    Likes Received:
    0
    I'm glad you have sorted your issue out :D
     
Loading...