SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: sub-domain masks with htaccess

  1. #1
    SitePoint Zealot
    Join Date
    Jun 2007
    Location
    Regina, SK, Canada
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sub-domain masks with htaccess

    I have a script automatically creating sub-domains through cPanel in PHP. But what I want are each of those subdomains (user.mydomain.com) to point to the exact same page - but I dont want the URL (user.mydomain.com) up top to change while they are browsing the site.

    Example. User's subdomain is created and is user1.mydomain.com, then goto that address and start clicking on links on that site, the url path up top does not move from user1.mydomain.com. How would I do this in .htaccess? Help

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

    Actually, what you're describing sounds like you have your script setup to create new directories for each of the subdomains which is NOT necessary - they can be pointed at the main domain's DocumentRoot which solves your problem. The other way, pointing them at their own subdirectory, you will NOT be able to share any files among the subdomains (nor access the main domain) without a redirection to the main domain (and showing the change in URL).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2007
    Location
    Regina, SK, Canada
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    jb,

    Actually, what you're describing sounds like you have your script setup to create new directories for each of the subdomains which is NOT necessary - they can be pointed at the main domain's DocumentRoot which solves your problem. The other way, pointing them at their own subdirectory, you will NOT be able to share any files among the subdomains (nor access the main domain) without a redirection to the main domain (and showing the change in URL).

    Regards,

    DK
    I want them to point to the document root, but when I do that through cPanel it changes the URL to the document root. Try going into cpanel and add a subdomain and then you have to add a redirect. I want to use the redirect but I dont want it to change the URL in the box.

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,318
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    jb,

    The MODIFIED CPanel that my host provides allows a new domain (or subdomain) to be added to my account with its DocumentRoot EITHER shared with my main domain OR sent to its own directory (based on the name of the domain). What I was referring to was, obviously, the first case.

    CPanel should NOT be redirecting away from the requested domain. Without access to your CPanel, I'm not sure how to tell you to proceed (DON'T give ANYONE access!!!).

    UH, OH! I just checked my host's panel and it does NOT allow a subdomain to be pointed at the domain's DocumentRoot AND, using the redirection WILL cause the location to change! That would appear to be a design flaw in CPanel (that it would allow domains to share a DocumentRoot but not subdomains) but you should be able to take care of that within the DNS record (BE CAREFUL as you could take your whole site down very easily) or have your host do that for you.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2007
    Location
    Regina, SK, Canada
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, basically I want to write this in an htaccess file...

    if there is any subdomain in the url (sub.domain.com),
    then transfer the page to www.mypage.com/page1.html,
    but keep the subdomain masked (sub.domain.com)

    Is this writable to an htaccess file using mod_rewrite

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,318
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    jb,

    It is NOT possible to change the (sub)DOMAIN without showing the new location. To effect any redirection (from a subdomain to the maindomain) will require that each subdomain have the same mod_rewrite statements redirecting to the maindomain.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    SitePoint Zealot
    Join Date
    Jun 2007
    Location
    Regina, SK, Canada
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your response! But then I was wondering how www.basecamphq.com does it. When you signup for an account you are given a subdomain like user.domain.com.
    Last edited by jboesch; Jul 10, 2007 at 08:20.

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,318
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    jb,

    They would have direct access to the httpd.conf so they would directly implement the dynamic mass hosting as described by apache.org - but would probably also be creating a new subdirectory for each user.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  9. #9
    SitePoint Zealot
    Join Date
    Jun 2007
    Location
    Regina, SK, Canada
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help on this matter DK. I was wondering if maybe then I could do this..

    have all subdomains created (trees.domain.com)
    forward to http://www.mydomain.com/index.php?subdomain=trees

    I know this could be done manually, but could it be done dynamically through htaccess? I realize I would first have to create the subdomain, but then could htaccess detect if there is a subdomain present then forward to that address?

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,318
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    jb,

    With Dynamic Mass Hosting (as Apache.org calls it), it would be a snap (so long as ABSOLUTE links are used within the subdomain scripts - if any) - but I would POINT all subdomains at the main domain's DocumentRoot and not use the absolute redirect. The subdomain redirection you've suggested would be simple:
    Code:
    # don't redirect the redirect!
    RewriteCond %{QUERY_STRING} !subdomain=
    # capture the subdomain
    RewriteCond %{HTTP_HOST} ^([a-z]+)\.domain\.com [NC]
    # but not www.
    RewriteCond %{HTTP_HOST} !^(www\.)domain\.com [NC]
    # then redirect anything to the index script
    # with the subdomain in the query string
    RewriteRule .? index.php?subdomain=%1 [QSA,L]
    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated 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
  •