SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict sporkit's Avatar
    Join Date
    Jan 2003
    Location
    DeKalb, IL
    Posts
    290
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    good redirection script

    hello. basicly i have bought some webspace but have a few different sites that i want to host. i was thinking i could place all the sites in different directories on my root. is there a redirection script that could append the directory to the url?

    maybe i could forward mysite.com to my webspace but then redirect that to mysite.com/sitedir/? im not sure whats the best way to go about this. any suggestions?

  2. #2
    SitePoint Zealot mrWoot's Avatar
    Join Date
    Jan 2004
    Location
    Wisconsin
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could do it with a switch statement and header() function
    -or-
    use .htaccess to do it

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.domain\.com/sitedi1r$ [NC]
    RewriteRule ^(.*)$ http://domain1.com/$1 
    RewriteCond %{HTTP_HOST} ^www\.domain\.com/sitedir2$ [NC]
    RewriteRule ^(.*)$ http://domain2.com/$1 
    RewriteCond %{HTTP_HOST} ^www\.domain\.com/sitedir3$ [NC]
    RewriteRule ^(.*)$ http://domain3.com/$1 [R=301,L]

  3. #3
    SitePoint Zealot mrWoot's Avatar
    Join Date
    Jan 2004
    Location
    Wisconsin
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I searched http://php.net/header for the answer.
    Quote Originally Posted by sam AT firestormltd DOT co DOT uk
    I have two domains pointing to my personal webserver, and as they are free they have limited options. I wanted each to go to a different subdirectory; my code was as as follows:

    PHP Code:
    <?php
    $servername
    =$_SERVER['HTTP_HOST'];
    if (
    $servername == "www.example.net") {
    header("Location: /subdir1/");
    exit;
    }elseif (
    $servername == "example.net") {
    header("Location: http://www.example.net");
    exit;
    } elseif (
    $servername == "www.example.com" || $servername == "example.com") {
    header("Location: /subdir2");
    exit;
    } else {
    header("Location: /subdir2/");
    exit;
    }
    ?>
    This has to come before anything else in the script, including HTML. Note that one part of the code redirects to www. if it is not specified. Hope someone finds this useful.


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
  •