Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2007
    Posts
    65
    Plugin Contributions
    0

    Default php check domain name and then redirect

    Here is my issue in a nutshell. I have 2 domain names:
    www.aacorvette.com is the primary
    www.aandacorvette.com is the secondary and setup as a domain alias

    I have an SSL for www.aacorvette.com and only want to use that one.

    Right now I have this to check and see if the URL is aacorvette or aandacorvette and redirect if incorrect.

    PHP Code:
    <? 
    $aa = 'www.aacorvette.com';
    $url = $_SERVER['SERVER_NAME']; 
    if ($url != $aa)
    {
      header('HTTP/1.1 301 Moved Permanently');
      header('Location: http://www.aacorvette.com');
    }
    ?>
    This seems to work OK, but if the user has http://aacorvette.com in the bar, it will forward them to the www.aacorvette.com address. (not that big of a deal)

    I tried to find a funtion that would use a "contains string in variable" but I couldn't find a good way.

    Is this the best way to do this? If so, is the best place to put the code in the tpl_main_page.php file?

    Thanks!

    Steve

  2. #2
    Join Date
    Oct 2007
    Posts
    65
    Plugin Contributions
    0

    Default Re: php check domain name and then redirect

    I forgot to add that I am on a windows box so I can't use .htaccess and I am on v1.3.8a.

  3. #3
    Join Date
    Jun 2008
    Location
    Washington, DC
    Posts
    785
    Plugin Contributions
    7

    Default Re: php check domain name and then redirect

    Try this:
    PHP Code:
    <? 
    // Must be www.aacorvette.com or will redirect
    if ( $_SERVER['SERVER_NAME'] != 'www.aacorvette.com')
    {
      header('HTTP/1.1 301 Moved Permanently');
      header('Location: http://www.aacorvette.com');
    }
    ?>
    Skip
    • 446F63746F722057686F •

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: php check domain name and then redirect

    Quote Originally Posted by forced View Post
    I tried to find a funtion that would use a "contains string in variable" but I couldn't find a good way.
    strstr() is a "is string contained in string" function.

    Quote Originally Posted by forced View Post
    Is this the best way to do this? If so, is the best place to put the code in the tpl_main_page.php file?
    I'd be inclined to put it in the master /index.php file in the root of your site.


    But better yet, I'd recommend researching your windows webserver configuration for smarter alternatives which would give you control similar to .htaccess. Your hosting company should be able to offer some ideas.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Oct 2007
    Posts
    65
    Plugin Contributions
    0

    Default Re: php check domain name and then redirect

    Thanks for the help guys! I tried using the strstr() but couldnt figure out how to make it work. Like if I needed to say true or false, etc. I will look further into something like a .htaccess file. In the meantime I am going to try Skip's way and put in the index.php. I can't believe I did all that with the variables and it was that easy!



    -Steve

 

 

Similar Threads

  1. Upgrading then moving to another domain name
    By etilyeti in forum Upgrading from 1.3.x to 1.3.9
    Replies: 4
    Last Post: 17 Oct 2011, 03:54 PM
  2. Modify the Write Reviews to Only Show First Name and then there Country Name
    By iDartsOnline in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 23 Mar 2011, 03:16 AM
  3. Creating Zen Cart Store, Then Change Domain Name
    By perkiekat in forum Installing on a Linux/Unix Server
    Replies: 6
    Last Post: 14 Sep 2009, 09:29 PM
  4. Transfer Site to new domain, and changeing domain name
    By dng in forum Installing on a Linux/Unix Server
    Replies: 3
    Last Post: 9 Mar 2007, 12:28 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR