Results 1 to 6 of 6
  1. #1
    Senior Member
    Join Date
    Aug 2004
    Location
    The land of the nerds
    Posts
    102

    Default Redirecting domains and PHP scripts

    Hi!

    I present you with a problem I faced and its solution I found today. If anybody has a better solution, feel free to inform me. I hope my solution can help other people who may have a similar problem.

    The problem: How to use more than one domain names with PHP scripts that normally work only on one domain.

    I recently decided to add two more domain names to my website. I made the domains to point to specific directories within my site:

    Adapedia.org -> wikinerds.org/adapedia

    nerdyPC.org -> wikinerds.org/nerdypc

    In these directories live two installations of MediaWiki, a PHP script.

    This script asks for a domain name when you install it. It seems unable to work with more than one domain name. So if www.adapedia.org redirects to wikinerds.org/adapedia, the script will not work and the user will get an error message.

    My solution:

    Step 1: I created two subdomains adapedia.wikinerds.org and nerdypc.wikinerds.org which point to the /adapedia and /nerdypc directories respectively. I re-installed the script to these subdomains. This step was not required, but I did that because I think subdomains are easier for the user to remember and may organise the script's cookies better.

    Step 2: I created two directories named /fwd/ap and /fwd/npc. I placed an index.html files in each directory. The index.html file contains a META redirect which transfer the user to the desired subdomain of wikinerds.org.

    Below you can see the template of the index.html file I used:

    Code:
    <html><head><title>Redirect Page</title> 
     <meta http-equiv="refresh" 
    content="0;url=http://subdomain.domain.tld/"> 
     </head> 
     <body> 
     <a href="http://subdomain.domain.tld/">Click here!</a> 
     </body> 
     </html>
    The number 0 controls how much time the user's browser will wait until it transfers the user to the destination. It's in seconds IIRC.

    Step 3: Using Westhost's Site Manager 2.0 I went to the Domain Management area and configured adapedia.org and nerdypc.org to redirect to /fwd/ap and /fwd/npc directories respectively.

    Result: The user can type www.adapedia.org and he/she sees a small page containing a link. If the user's browser supports redirects, the user will be transferred to adapedia.wikinerds.org. If it doesn't, the user can click the link. The PHP script now works correctly since it only operates in the adapedia.wikinerds.org subdomain. Problem solved!

    Possible problems: Some search engines don't like META redirects because they seem to be used a lot by spammers. Some browsers may not support META tags.

    If you think this guide is useful, you may copy and alter it under the terms of CreativeCommons Attribution 2.0 license.
    I am just a customer of WestHost trying to help others. I own Wikinerds.org and you can also see my personal homepage and my blog!

  2. #2
    Senior Member torrin's Avatar
    Join Date
    May 2003
    Location
    Vista, CA
    Posts
    534

    Default

    Quote Originally Posted by nsc
    Possible problems: Some search engines don't like META redirects because they seem to be used a lot by spammers. Some browsers may not support META tags.

    The fix for this is to create an .htaccess file in that directory and put something like this in it . . .

    Code:
    redirect /index.html http://www.yourdomain.com/some/dir/index.html
    Of course, change the place it's redirected to. Since you have 2 domains, you'll have to create 2.

    Credit where credit is due. This information was stolen from another post in the forum. If I find it, I'll post it here.

    Found it . . . http://forums.westhost.com/phpBB2/vi...hp?p=8480#8480

  3. #3
    Senior Member
    Join Date
    Aug 2004
    Location
    The land of the nerds
    Posts
    102

    Default

    I think htaccess files dont work properly on my site, but I haven't tested them much (or perhaps I was just wrong in my syntax when composing my htaccess). I will test more when I have time to see what I did wrong or what prevents me using htaccess.
    I am just a customer of WestHost trying to help others. I own Wikinerds.org and you can also see my personal homepage and my blog!

  4. #4
    Senior Member torrin's Avatar
    Join Date
    May 2003
    Location
    Vista, CA
    Posts
    534

    Default

    You should also be able to put that command in your httpd.conf file inbetween <directory> tags. In fact the apache documentation recommends that.

    http://forums.westhost.com/phpBB2/viewtopic.php?t=1877

  5. #5
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,721

    Default

    .htaccess should work on all WH accounts I belive. WH uses it on your site to control access to things like phpMyAdmin.
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  6. #6
    Junior Member
    Join Date
    Apr 2006
    Posts
    17

    Default

    I use a PHP redirect and it works quite well
    <?php
    $host = $_SERVER['HTTP_HOST'];
    $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    $extra = 'www';
    echo $host.$uri.$extra;
    header("Location: http://$host$uri/$extra");
    exit;
    ?>

Similar Threads

  1. two domains - php/post enabled on both?
    By bearbr in forum Domain names & DNS
    Replies: 9
    Last Post: 03-23-2006, 05:30 PM
  2. Form to email, php alternative
    By howard in forum PHP / MySQL
    Replies: 1
    Last Post: 09-29-2005, 06:11 PM
  3. Multiple BBs for multiple domains?
    By WolfStar76 in forum PHP / MySQL
    Replies: 3
    Last Post: 01-18-2005, 07:32 PM
  4. How to know/detect if ppl using my php script to send spam
    By firebirdfan in forum CGI Scripts / Perl
    Replies: 3
    Last Post: 01-29-2004, 12:16 PM

Posting Permissions

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