Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

This is a discussion on mod_rewrite fo a subdomain in the Shared & Semi-Dedicated forum
Here's what I want to happen: When a user connects to any subdomain (mysubdomain1.mydomain.com, mysubdomain2.mydomain.com etc) they should see the contents of www.mydomain.com/content . However, ...

  1. #1
    JPC Addict
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    135

    mod_rewrite for a subdomain

    Here's what I want to happen:
    When a user connects to any subdomain (mysubdomain1.mydomain.com, mysubdomain2.mydomain.com etc) they should see the contents of www.mydomain.com/content. However, the address bar should still show mysubdomain1.mydomain.com.

    Is this possible with mod_rewrite?
    Last edited by uprightdog; 10-08-2005 at 07:14 AM.

  2. #2
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,307
    Yes, but I'm not sure you'd want to do it that way, unless I'm mis-understanding your needs.

    When you say "/content" by that do you mean your main index page, then any relative links from that?

    If so, you could also ask support to add a DNS wilcard for not-specifically-listed subdomains, that would cause *.domain.com to resolve to the same place, and whatever they had in the url would remain.


    A word of caution might be in order: The search engine world (ie Google) won't like seeing the same content on different subdomains, and will penalize most, all, or all-but-one of them.

    Good luck!

  3. #3
    JPC Addict
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    135
    Quote Originally Posted by Ron
    Yes, but I'm not sure you'd want to do it that way, unless I'm mis-understanding your needs.
    I wouldn't?

    Quote Originally Posted by Ron
    When you say "/content" by that do you mean your main index page, then any relative links from that?
    Yes.

    Quote Originally Posted by Ron
    A word of caution might be in order: The search engine world (ie Google) won't like seeing the same content on different subdomains, and will penalize most, all, or all-but-one of them.
    Well, each subdomain's content will differ slightly, as PHP will pull some unique content from the DB according to the subdomain used. At least, that's the plan.

  4. #4
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,307
    Cool. I think your best bet might be to go the wildcard route, unless you have a limited number of subdomains for which you want to do this.

    Otherwise, there are about 100 ways to accomplish what you want to do.

    You could have your main code in a common location, and soft link to the code. Each subdomain's index.php would just be a link to the common code. You could have a php include() in each subdomain's index.php file that would just include the same code in each case.

    You could set up .htaccess in each subdomain (or if you're lucky in your public_html directory and have it inherited to each subdomain, but I've found that not to be 100% relaiable and frequently caused me fits) That would internally redirect to a php program... but working from within a subdomain structure, now you're going to be mucking around with resetting the rewrite base, and I think making things incredibly complicated, when a simple wildcarding would do just fine for your purposes.

    If you really really want to set up a subdomain for each different term, perhaps a note to support to point the subdomain to your www directory would suffice for your purposes, too.

    Good luck!

  5. #5
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,775
    Quote Originally Posted by uprightdog
    When a user connects to any subdomain (mysubdomain1.mydomain.com, mysubdomain2.mydomain.com etc) they should see the contents of www.mydomain.com/content. However, the address bar should still show mysubdomain1.mydomain.com.

    Is this possible with mod_rewrite?
    This is how I do it...
    Code:
    #RedirectMatch multiple subdomains (domain.com/subdomain -> subdomain.domain.com) - VinDSL
    RedirectMatch 301 /(alpha|beta|civic|download|pilot|info)/(.*)$ http://$1.lenon.com/$2
    EDIT: I suppose I should supply some examples...
    Last edited by Vin DSL; 10-08-2005 at 03:33 PM.
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

  6. #6
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,307
    I don't think that's the issue, vin....

    He's not looking to direct domain.com/subd to subd.domain.com
    He's looking to internally rewrite subd.domain.com to www.domain.com

  7. #7
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,775
    Quote Originally Posted by Ron
    I don't think that's the issue, vin....

    He's not looking to direct domain.com/subd to subd.domain.com
    He's looking to internally rewrite subd.domain.com to www.domain.com
    Ah! Okay...

    In that case, yes, that's possible, but you better have a pretty good knowledge of mod_rewrite. That sort of stuff is mind-boggling, even for me. I know mod_rewrite backwards, forwards, and upside down, but it still gives me a headache, literally...

    Basically, what you need to do is configure .htaccess to do the rewrites, then call them up in your header. Sounds simple enough, but it probably took me a year to figure this out.
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

  8. #8
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,775
    Quote Originally Posted by Ron
    I don't think that's the issue, vin....

    He's not looking to direct domain.com/subd to subd.domain.com
    He's looking to internally rewrite subd.domain.com to www.domain.com
    You know, I was just thinking...

    If all the links to content on the subs are written using relative links (ahem), as they properly should be, wouldn't the redirect[s] take care of his problem?

    Click on some stuff in the examples I provided. They retain the correct name structure in the addy bar, right? Isn't this what he's talking about?
    Last edited by Vin DSL; 10-08-2005 at 03:45 PM.
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

  9. #9
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,307
    All he needs is to have support wildcard his domain to his www folder, then use php to determine which subdomain was requested.

    Something like
    PHP Code:
    <?php
    // Detect the subdomain and take action based upon it
    // Ron, October 08, 2005
    // Note you must substitue your domain name in lower case in this code example.

    $domainstart strpos(strtolower($_SERVER['HTTP_HOST']),".mydomain.com");

    if (
    $domainstart === false)
    {
    // no ".mydomain.com" found, so there is no subdomain!
    // do whatever you want with no special subdomain
    }
    else
    {
       
    $subdomain substr($_SERVER['HTTP_HOST'],0,$domainstart);
       switch (
    $subdomain)
       {
       case 
    "www":
          echo 
    "got your www here<br>";
          break;
       case 
    "highvaluekeyword":
          echo 
    "spam me now, I'm a highvaluekeyword<br>";
          break;
       default:    
    // Any subdomain name you weren't expecting
          
    echo "I'm off to google this";
          break;
       }
    }
    ?>
    No rewriting, either internal or external, required.
    There ya go. Have a blast.

  10. #10
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,307
    Naaaah vin, your stuff works well for what you're doing, but it's not what I get out of his request....


    He wants to have people going to test.lenon.com and foo.lenon.com to be pointed to the content located at www.lenon.com but still see the different subdomains in the addy bar.

    There are a hundred ways to do this, I think the easiest is as coded.

  11. #11
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    I agree with Ron. Just direct *anything*.domain.com to public_html using a DNS wildcard and use the HTTP_HOST variable to figure out what content to display. Easy to code, easy to maintain, and it requires no "unusual" server overhead--just simple HTTP requests and basic scripting.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  12. #12
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,307
    I would like to point out that with wildcarding, existing specific subdomains and future specific subdomains will all properly resolve to the proper subdomain subdirectory as well.

    When I first started with Aletia (I think) they used to wildcard automatically... I think when Jag took over they dropped that. Or it could have been when I moved from another provider to Aletia that it was dropped.

    Anyway, specific subdomains worked fine with wildcarding in place.

  13. #13
    Loyal Client the_ancient's Avatar
    Join Date
    Feb 2004
    Posts
    3,386
    I seem to think Jag did the wildcards automatically at one time, but I could be wrong on that....

    I wonder why they dont anyway?

  14. #14
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,307
    I actually ran into a problem with it a bunch of years ago.

    Someone had a typo in my URL on their page.

    The typo was http://%0a%0dwww.domain.com . In other words, there was a line fieed/carriage erturn embedded in my url.

    Google picked it up, and that became the primary url for my site in their index. Fortunately, I was able to construct a search and found the site where the error was started (it was a guestbook of a friend's site!) and I was able to get the friend to remove the link. It took about 6 months to get straightened away.

    Google suggested that it was a bad idea to have a wildcarded domain, but I don't recall if they gave any other answers. I think I might have even discussed it on the net elsewhere (here?), but it was sooo long ago....

  15. #15
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,775
    Quote Originally Posted by Ron
    I actually ran into a problem with it a bunch of years ago.

    Someone had a typo in my URL on their page.

    The typo was http://%0a%0dwww.domain.com...
    I get stuff like that every so often. Here's how I handle it (using your example)...
    Code:
    #Deny particularly nasty referers - VinDSL
    SetEnvIfNoCase Referer "^http://%0a%0dwww.domain.com" bad_ref=yes   [NC]
    RewriteCond %{ENV:bad_ref} ^yes$
    RewriteCond %{HTTP_REFERER} ^(.*)$
    RewriteRule ^(.*)$ %1                                               [R=301,L]
    After a while, they'll go away...
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

Page 1 of 2 12 LastLast

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
  •