Mod rewrite and PHP

Discussion in 'PHP' started by DavidHall, Aug 10, 2007.

  1. #1
    Hello there,

    What I am looking to do is load....

    mysub.mydomain.com

    so it just loads....

    mydomain.com

    Then with php I'm looking to extract the 'mysub' part of the name to a variable. I want the site to always have the subdomain in place though, I don't want it to fully redirect.

    Any clues?

    Cheers
     
    DavidHall, Aug 10, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    <IfModule mod_rewrite.c>
    RewriteEngineOn
    RewriteCond %{HTTP_HOST} ^([^.]).mydomain.com
    RewriteRule ^(.*)$ /$1?subdomain=%1 [QSA,L]
    </IfModule>

    Not 100% sure it will work though.
     
    krt, Aug 10, 2007 IP
  3. DavidHall

    DavidHall Active Member

    Messages:
    565
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Thanks, can't test it at the moment as I'm not at home.

    However, I'm not looking to put the subdir name in the url, but looking to use the PHP script to extract the subdomain. Do I even need mod rewrite for this? Can I just set up a wild card for the domain and then extract the subdomain in the script?
     
    DavidHall, Aug 10, 2007 IP
  4. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Yes, I know. The mod_rewrite solution I posted does not change what the user sees in the address bar.
     
    krt, Aug 12, 2007 IP