Find the answer to your Linux question:
Results 1 to 9 of 9
I'm working on a website for a Linux User Group I'm starting. I have created a subdomain on my site for it, and I have a directory with a little ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496

    [SOLVED] Website Subdomain Redirect


    I'm working on a website for a Linux User Group I'm starting. I have created a subdomain on my site for it, and I have a directory with a little test page in it.

    My site is:

    http://www.techiemoe.com

    My subdomain is:

    http://klug.techiemoe.com

    I'm trying to make it so that if someone navigates to "klug.techiemoe.com" they get redirected to this address, which points to the test page:

    http://www.techiemoe.com/klug/

    I've attempted this several ways. My host (Brinkster) apparently does not allow you to redirect using the .htaccess file. I've tried modifying this file to say this:

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^klug.techiemoe.com
    RewriteCond %{REQUEST_URI} !^/klug/
    RewriteRule (.*) /klug/$1 [L]
    I've tried several permutations of this I've found scattered around the internet. None of them seem to work. Several suggestions said that my host may not allow PHP to be run from the .htaccess file.

    Next I looked in the support section of my host, which suggested I use ASP, PHP, or JavaScript. For obvious reasons, I wanted to try the JavaScript. I've added this to the < head > section of my index.htm file:

    Code:
    <script language="javascript">
    
    var whois=location+" "
    
    if (whois.indexOf("techiemoe.com") != -1)
    
              { window.location ="index.htm" }
    
    
    
    if (whois.indexOf("www.techiemoe.com") != -1)
    
              { window.location ="index.htm" }
    
    if (whois.indexOf("klug.techiemoe.com") != -1)
    
              { window.location ="klug/" }
    
    </script>
    This results in some strange behavior. When the user types "klug.techiemoe.com" it still loads the main page. However when you click on the title "Techiemoe.com" it tries to redirect to this URL:

    Code:
    http://www.techiemoe.com/klug/1
    I managed to throw in another .htaccess file to redirect the inevitable 404 to the main page for the LUG, but I'd really like to get this working properly. Any suggestions?
    Registered Linux user #270181
    TechieMoe's Tech Rants

  2. #2
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Bump.......
    Registered Linux user #270181
    TechieMoe's Tech Rants

  3. #3
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Moved and bumped...
    Registered Linux user #270181
    TechieMoe's Tech Rants

  4. #4
    Linux Engineer jledhead's Avatar
    Join Date
    Oct 2004
    Location
    North Carolina
    Posts
    1,077
    so if you type the address' in do they go to their own website or does that not even work? do they both go to the same place.

    here is a refresh that I use
    Code:
    <html>
    <head>
    <meta HTTP-EQUIV="REFRESH" content="5; url=http://destination_url.com">
    </head>
    <body>
      
    </body>
    </html>
    this is the index.html page and when it loads up it redirects to the destination specified. the content="5 dictates the refresh time, set to lower for quicker redirection.

  5. #5
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by jledhead View Post
    so if you type the address' in do they go to their own website or does that not even work? do they both go to the same place.
    Yes, regardless of whether I type in klug.techiemoe.com or TechieMoe.com they both end up on my main index page.
    Today, for whatever reason, if you type in the subdomain it gives you an error 500. I'm looking into it.

    here is a refresh that I use
    Code:
    <html>
    <head>
    <meta HTTP-EQUIV="REFRESH" content="5; url=http://destination_url.com">
    </head>
    <body>
      
    </body>
    </html>
    this is the index.html page and when it loads up it redirects to the destination specified. the content="5 dictates the refresh time, set to lower for quicker redirection.
    I see what you're talking about but I don't see how it applies to this situation. I'm not trying to redirect all traffic from my site to the other index page, only traffic that comes in under the subdomain... could you explain this one to me a bit more?
    Registered Linux user #270181
    TechieMoe's Tech Rants

  6. #6
    Linux Engineer jledhead's Avatar
    Join Date
    Oct 2004
    Location
    North Carolina
    Posts
    1,077
    my post would work if your subdomains were served from different directories. when you set these up are you settings up virtual hosts or are you using a web admin like cpanel to do it? do you have access to your apache configuration?

  7. #7
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by jledhead View Post
    my post would work if your subdomains were served from different directories.
    The way I have it set up now is everything is inside my main web directory, /public_html/, and everything directs to the index.htm file in there. The other index.htm for KLUG is in the subdirectory /public_html/klug/.

    when you set these up are you settings up virtual hosts or are you using a web admin like cpanel to do it? do you have access to your apache configuration?
    I did not set up the subdomain myself. Someone at my hosting company did it. I do not think I have access to my server configuration.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  8. #8
    Linux Engineer jledhead's Avatar
    Join Date
    Oct 2004
    Location
    North Carolina
    Posts
    1,077
    how about something like this
    Code:
    <?PHP
    
    switch ($HTTP_HOST) {
    
    case "www.firstdomain.com":
    header("Location: /firstdirectory/index.php");
    break;
    
    case "www.seconddomain.com":
    header("Location: /seconddirectory/index.php");
    break;
    
    case "www.thirddomain.com":
    header("Location: /thirddirectory/index.php");
    break;
    
    default:
    header("Location: site_index_page.html");
    
    )
    
    ?>
    I found that here How to redirect user based on domain requested? [Archive] - PHPBuilder.com

  9. #9
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Aha! Not that exact thing, but the same idea in JavaScript, seems to have done the trick. Thanks for steering me in the right direction.
    Registered Linux user #270181
    TechieMoe's Tech Rants

Posting Permissions

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