SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    In my house
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Delivering different css dependent on domain

    I use Cpanel to run my server - very good - and it allows me to park a second domain onto my first domain so that the pages have whichever domain you are visiting as the url in the browser - i.e.

    www.example.com/index.html
    www.test.com/index.html

    The index.html files are the same file.

    However I want to be able to deliver a different css file based upon which domain is being viewed - so that I deliver the same content but with a different skin for each.

    Can this be done with Mod rewrite or any other apache server side wizardry and if so how.

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

    Yes, it can be done via mod_rewrite pretty easily. Using example.css as example.com's css file and test.css as test.com's css, put example.css in your scripts then use:
    Code:
    RewriteEngine On
    RewriteCond %[SERVER_NAME] test\.com
    RewriteRule example\.css$ test.css [L]
    BTW, that's not parking, you're sharing the host directory. Parking doesn't show a website but merely stores the DNS.

    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
    SitePoint Member
    Join Date
    Dec 2004
    Location
    In my house
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant - nice and easy - that's what I was hoping for.

    Many thanks!

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

    Looking back at my post, those should have been curly braces, not square braces, around the SERVER_NAME. Sorry about that, I must've been asleep.

    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

  5. #5
    SitePoint Member
    Join Date
    Dec 2004
    Location
    In my house
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh dear didn't work. I didn't get anything happening - even with the correct brackets!

    After a bit of fiddling about I ended up with this:

    Code:
    RewriteEngine On
    RewriteCond %{SERVER_NAME} domain2\.com
    RewriteRule typography\.css$ /assets/typography2\.css [L]
    When I put the domain1.com in place of domain2.com I do get the typography2.css showing - but for both sites.

    I tried paths from the root for both parts of the rewrite rule as well - the one above - with just the file name for the first part and the path from root for the second part.

    I also added an escape before the '.' for typography2.css.

    Any idea?

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

    BUMMER!

    I gave you the "updated" version of the code 'cause I've been reading about $_SERVER variables and didn't trust my old stand-by: HTTP_HOST. Give this a try:
    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} domain2\.com$
    RewriteRule typography\.css$ /assets/typography2.css [L]
    Do NOT excape characters in the redirect, only the regex!

    I'll be out of the office for a while but I'll check back later to see if that corrected the problem.

    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

  7. #7
    SitePoint Member
    Join Date
    Dec 2004
    Location
    In my house
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DK - works a treat! Many thanks!

    Simon

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

    It's Party Time!



    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
  •