Redirect multiplle domains to same page with different query string param - How?

Discussion in 'Site & Server Administration' started by Quimbly, Jan 12, 2011.

  1. #1
    Hi all,
    I'm currently hosting multiple domains on a single web space. The files for each website are located in different folders:

    domain1.com in /public_html/folder1
    domain2.com in /public_html/folder2
    domain3.com in /public_html/folder3

    Currently the redirects are handled by some behind-the-scenes mechanism, which I can't discern. It's managed through the cPanel as add-on domains.

    All of the sites are the same, with the exception of some personal data, some photos, and some links. So, I wrote some php code to swap out these details, based on an ID from the query string. Everything is ready, but now I'm looking for a way to use my .htaccess to redirect requests for each of the domain names to the *same* folder and file, but with a different query string parameter.

    E.g.
    domain1.com -> /public_html/folder4/index.php?id=1
    domain2.com -> /public_html/folder4/index.php?id=2
    domain2.com -> /public_html/folder4/index.php?id=2

    Also, obviously, the domain names needs to be preserved:

    domain1.com -> domain1.com/index.php?id=1
    domain2.com -> domain2.com/index.php?id=2
    domain3.com -> domain3.com/index.php?id=3


    I'm a novice with .htaccess, and so am having one heck of a time getting this working.

    Can some kind soul out there help me out with this one?

    Thanks!
     
    Quimbly, Jan 12, 2011 IP
  2. atxsurf

    atxsurf Peon

    Messages:
    2,394
    Likes Received:
    21
    Best Answers:
    1
    Trophy Points:
    0
    #2
    use
    RewriteCond %{HTTP_HOST}
    HTML:
    in .htaccess
     
    atxsurf, Jan 12, 2011 IP
  3. Quimbly

    Quimbly Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for the reply. I've been experimenting with RewriteCond but I haven't had any luck.

    Can you give me an example of how to do this properly?

    Here's what I've tried, based on stuff I've pieced together in dozens of posts around the web:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www.)?primarydomain.com$

    RewriteCond %{REQUEST_URI} !^/primarydomain.com/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ /primarydomain.com/$1

    RewriteCond %{HTTP_HOST} ^(www.)?primarydomain.com$
    RewriteRule ^(/)?$ primarydomain.com/index.htm [L]


    The problem here is that the HTM file is served properly, but none of the images are.
    Any ideas?
     
    Quimbly, Jan 12, 2011 IP