Results 1 to 2 of 2

Thread: www. redirecting to a no sub-domain url of the same url

  1. #1
    Join Date
    Dec 2009
    Posts
    7

    www. redirecting to a no sub-domain url of the same url

    Lately I've been having problems with cookies and their domains effecting their functionality with the www. subdomain. One of the the methods Ive seen other web designers use to resolve this issue is by redirecting ANY www. subdomain to the same address without the www.. Is there some kind of javascript / PHP script that I can use to check the current URL and redirect them to the same URL without the www.?

  2. #2
    Join Date
    Jan 2004
    Location
    Out There Somewhere
    Posts
    48
    Put above all html Do not put the http://

    Code:
    <?php
    $preferreddomain = 'YOURDOMAINNAME.com';   // without www
    if ($_SERVER['HTTP_HOST'] != $preferreddomain || preg_match('/www\.'.$preferreddomain.'/i', $_SERVER['HTTP_VIA']))
    { header($_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently');
      header("Location: http://" . $preferreddomain . $_SERVER['REQUEST_URI']);
      exit();
    }
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    <HTML><HEAD>

Similar Threads

  1. Domain Names 101.9 - Net Real Estate--China Net Technology Limited
    By Alao25 in forum Web Hosting and Domain Names
    Replies: 1
    Last Post: 08 Nov 2007, 08:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •