How can I make sure someone uses www.domain.com

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • -Oz-
    Senior Member
    • Mar 2004
    • 545

    How can I make sure someone uses www.domain.com

    It is very easy to make sure that a user uses http://www.domain.com instead of just http://domain.com with a simple piece of PHP code placed at the top of every page.

    PHP Code:
    <?php 
    $server 
    getenv("HTTP_HOST"); 

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

    ?>
    Courtesy of sdjl

    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.
    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.

    Courtesy of ndns
    Last edited by -Oz-; 04-23-2004, 01:06 AM.
    Dan Blomberg
Working...