SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    0 Post(s)
    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:
    Addon Domain: (located in a subfolder named xyz, under

    Before adding the second domain, I was using the following line to redirect traffic to my phpbb folder...
    redirect /index.html
    Now I am unable to access the new, addon domain. All requests to are forwarded to My host says the redirect is to blame. is what I need to achieve.
    1. All requests for or are directed to I also want to make sure the path, "" still shows in the browser's address bar.

    2. All requests for or are direct to 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.

    # Rewrite /index.html to /phpbb/index.php for 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 (shows directory structure) (shows directory structure) (500 error) (goes to rather than, 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.


  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    20 Post(s)
    3 Thread(s)

    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, and where's root is the xyz subdirectory of 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 requests to the xyz subdirectory (NOT a permanent redirect, though).

    Let's correct your's root .htaccess first:
    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's root directory, I changed your absolute redirect to a relative and added the Last flag.

    Requests to 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'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 can't see the'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 is directed to the xyz subdirectory?

    Catch you later.


    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


Posting Permissions

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