SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Mod_Rewrite / Redirect Help for Addon Domain

    I am having difficulty redirecting my existing domain and a recently added domain to their correct locations.
    Primary Domain: abc.com
    Addon Domain: xyz.com (located in a subfolder named xyz, under abc.com)

    Before adding the second domain, I was using the following line to redirect traffic to my phpbb folder...
    Code:
    redirect /index.html http://www.abc.com/phpbb/index.php
    Now I am unable to access the new, addon domain. All requests to xyz.com are forwarded to http://www.abc.com/phpbb/index.php. My host says the redirect is to blame.

    Ok...here is what I need to achieve.
    1. All requests for http://www.abc.com or http://abc.com are directed to http://www.abc.com/phpbb/index.php. I also want to make sure the path, "http://www.abc.com/phpbb/index.php" still shows in the browser's address bar.

    2. All requests for http://www.xyz.com or http://xyz.com are direct to http://www.xyz.com and look to the "xyz" subfolder as it's "root".

    It was suggested to me to use the rewrite command for both domains. Below is the code I used and the results.

    Code:
    # Rewrite /index.html to /phpbb/index.php for abc.com only 
    RewriteCond %{HTTP_HOST} ^(www\.)?abc\.com 
    RewriteRule ^index\.html$ /phpbb/index.php [L] 
    # 
    # Rewrite xyz domain to subfolder 
    RewriteCond %{HTTP_HOST} ^www\.xyz\.com 
    RewriteCond %{REQUEST_URI}!/xyz/ 
    RewriteRule (.*) /xyz/$1 [L]
    Here are my results
    http://www.abc.com (shows directory structure)
    http://abc.com (shows directory structure)
    http://www.xyz.com (500 error)
    http://xyz.com (goes to http://xyz.com rather than http://www.xyz.com, but does load the correct index.html file)

    I also tried prefacing the code with...RewriteEngine on...but it did not make a difference. Any help would be appreciated.

    Thanks!
    Brian

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Brian,

    First, sorry to have ignored your post for so long - it seemed to be asking about things I'm weak in so I was "volunteering" others to answer.

    Okay, you have two domains, abc.com and xyz.com where xyz.com's root is the xyz subdirectory of abc.com. That, of course, is specified by your httpd.conf file in the Virtual Hosts section (my weakness - but I'm learning).

    Your problem is that you want to redirect abc.com requests to the xyz subdirectory (NOT a permanent redirect, though).

    Let's correct your abc.com's root .htaccess first:
    Code:
    RewriteEngine On
    # handle empty {REQUEST_URI} string
    RewriteRule ^$ phpbb/index.php [L]
    # handle request for index.html
    RewriteRule ^index\.html$ phpbb/index.php [L]
    First, I don't understand the "redirect" so I've changed it to use mod_rewrite for the redirections. Second, I've made the index.html be the START (and END) of the {REQUEST_URI} string and escaped the dot in index.html (so it will ONLY match the dot. Third, since you're already in the abc.com's root directory, I changed your absolute redirect to a relative and added the Last flag.

    Requests to xyz.com should NOT be able to access this .htaccess so it should be okay.

    Okay, as for your #1 request, I've added the "blank {REQUEST_URI} RewriteRule. HOWEVER, you've changed the groundrules on my by wanting to show the redirect! Okay, change both "[L]" entries to "[R=301,L]" to show the actual redirects.

    Your #2 request is handled by httpd.conf as xyz.com's Virtual Host has set DocumentRoot path-to/xyz so you need do nothing more.

    As you can see, you don't need to go into RewriteCond(itions) to assess {HTTP_HOST} 'cause xyz.com can't see the abc.com's root directory (where the above .htaccess is located). Of course, this changes if your host has setup xyz to go to abc's root but that's NOT what you described.

    If you need to take this further, please advise:

    1. Do you have access to the httpd.conf file?
    2. Can you confirm that xyz.com is directed to the xyz subdirectory?

    Catch you later.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •