SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Custom .htaccess wildcard subdomains?

    Is there a method so I can make $username.mysite.com point to www.mysite.com/index.php?username=$username or mysite.com/index.php?username=$username?

    I have wildcard subdomains turned on yet I cannot find the method to do this... can someone please help? Thank you.
    Have a good day.

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

    Yes, but it will depend upon where your subdomains are pointed (after all, they ARE separate domains). If they're pointed at www.example.com (share the DocumentRoot), then
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
    RewriteCond %{HTTP_HOST} ^((www\.)?([a-z]+)\.)example\.com [NC]
    RewriteRule .? http://www.example.com/index.php?username=%3 [L]
    Note that this will change the domain name shown in the location box (which is what you requested).

    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 Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot!
    Have a good day.

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

    I'll take it that I guessed correctly at your configuration and all is well.

    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 Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi sorry actually that code didn't work. I came up with the solution though:
    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
    RewriteRule ^$ /profile.php?username=%2 [QSA,nc]
    Have a good day.

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

    WHY the QSA and NC in the RewriteRule (and NO Last flag)?

    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 Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The last flash seems to return an error.
    Have a good day.

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    D884,
    Code:
    # .htaccess in DocumentRoot (Apache 2.x)
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
    RewriteRule ^$ http://www.domain.com/profile.php?username=%2 [L]
    Regards,

    DK
    Last edited by dklynn; Nov 3, 2008 at 15:23. Reason: Absolute redirect needed to prevent looping.
    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

  9. #9
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it to work.

    Thanks for the time you gave to help me.
    Have a good day.

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


    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

  11. #11
    Always learning viveknarula's Avatar
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can we use it without Wildcard DNS enabled ? I am on a shared hosting where my hosting provider does not provide Wildcard DNS option enabled.

    Please help

    Thanks

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

    Yes, but ONLY if you have all possible (reasonable ... acceptable) subdomains identified AND parked on the main domain's DocumentRoot.

    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

  13. #13
    Always learning viveknarula's Avatar
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    vk,

    Yes, but ONLY if you have all possible (reasonable ... acceptable) subdomains identified AND parked on the main domain's DocumentRoot.

    Regards,

    DK
    So do you mean that we should first create subdomain from the cpanel/hosting panel as ususal.

    DK, i would like to do the same thing as D884 is mentioning therefore creating username as subdomains. So username will be dynamic.

    Thanks !!

  14. #14
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi vive I don't think its possible if you can't configure the server to use a wildcard for that site. The htaccess just points it to where its going where as the server configuration actually enables the wildcard sub domains. If you can't do it then I would look for a new host because there are many shared cheap hosts that allow wildcard sub domains.
    Have a good day.

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

    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

  16. #16
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    Hi,

    I have enabled wildcard dns...

    And i have copied your code to htaccess then also it is not working...

    With Regards,
    Babu.M

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

    Welcome to SitePoint's Apache forum!

    Where are the wildcard subdomains pointed? Where is the .htaccess file located? Check out the page at http://httpd.apache.org/docs/2.2/vhosts/mass.html for more information about these critical aspects.

    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
  •