SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Drachten
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Different index file based on domain name

    Hi,

    I have 3 domains and all three are pointing to one directory on the server (ServerAlias). I am trying to accomplish the following:

    - When a user browses to http://www.domain1.com/ he should be directed to the following: http://domain1.com/index_domain1.html
    - When a user browses to http://www.domain2.com/ he should be directed to the following: http://domain2.com/index_domain2.html
    - When a user browses to http://www.domain3.com/ he should be directed to the following: http://domain3.com/index_domain3.html

    URLs like http://domain3.com/this_is/some_file.html and http://domain2.com/this_is/some_file.html don't have to be rewritten. (so actually the only thing I want to rewrite is the index file)

    I tried to use mod_rewrite, but I could not figure out how to achieve this...


    Any suggestions?

    Thanks in advance!

    - Jasper
    Last edited by formmailer; Apr 6, 2005 at 02:41. Reason: clarify post

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

    Quote Originally Posted by formmailer
    [snip]
    - When a user browses to http://www.domain1.com/ he should be directed to the following: http://domain1.com/index_domain1.html
    - When a user browses to http://www.domain2.com/ he should be directed to the following: http://domain2.com/index_domain2.html
    - When a user browses to http://www.domain3.com/ he should be directed to the following: http://domain3.com/index_domain3.html

    [snip] ...(so actually the only thing I want to rewrite is the index file) ... [snip]
    I'll assume that you have mod_rewrite and .htaccess available to you -- otherwise, have a look at the article at datakoncepts.com/seo.

    Quite obviously, the first thing that mod_rewrite has to do is to determine which virtual server is playing host (which it should do automatically). Then it needs to determine whether the {REQUEST_URI} is empty (blank) so that it can redirect to the appropriate domain's index (invisibly). Piece of cake!
    Code:
    RewriteEngine On
    RewriteRule ^$ index_%{HTTP_HOST}.html [L]
    If you really don't want the www. and .com in the %{HTTP_HOST} string, you'll need to create a rewrite condition to isolate just the (lowercase ONLY) domain name. The following should eliminate the www. and .com - you can change that if necessary:
    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www\.)?([a-z]+)\.com$ [NC]
    RewriteRule ^$ index_%2.html [L]
    Ho-kay, that should do it (for your specific request). Don't forget, I charge DOUBLE if you change your request 'cause you really wanted something else!

    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

  3. #3
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    David,
    wouldn't mod_alias be simpler in that situation?

  4. #4
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Drachten
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by dklynn
    If you really don't want the www. and .com in the %{HTTP_HOST} string, you'll need to create a rewrite condition to isolate just the (lowercase ONLY) domain name. The following should eliminate the www. and .com - you can change that if necessary:
    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www\.)?([a-z]+)\.com$ [NC]
    RewriteRule ^$ index_%2.html [L]
    Ho-kay, that should do it (for your specific request). Don't forget, I charge DOUBLE if you change your request 'cause you really wanted something else!

    Great! Thanks David!

    - Jasper

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    duuudie,
    Quote Originally Posted by duuudie
    David,
    wouldn't mod_alias be simpler in that situation?
    It probably would be - **IF** I understood it better. Does it allow more than a page-for-page redirect?

    Aw, I'm just human and run to what's familiar when trying to solve a problem. That said, if you prod me enough times, I may actually learn something and that would be grand!

    formmailer,

    That's about using the most appropriate tool that's available. On the other hand, "if it ain't broke, don't fix it". mod_rewrite uses regex to make it extremely powerful - at a cost of processing by Apache. I don't think I've overused it so take your pick.

    Anyway, glad we got it resolved for you!

    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

  6. #6
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey David, I was the one hoping to learn something from you

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    duuudie,

    Oh, the pressure's overwhelming!

    Yeah, that mod_alias looks interesting but you should see what pippo's come up with in this thread! I can't wait for his "idea" to germinate.

    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

  8. #8
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •