Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post

    Mod rewrite - creating fake subdomains

    I was wondering if someone can help me out with a small issue I am having with mod rewrite; I have experience rewriting URL's but am having trouble with this one..

    Basically what I want to do is this..

    username.domain.com = www.domain.com/users/username/

    Also.... any other page that the user requests on the sub-domain would redirect to the appropriate page... such as..

    username.domain.com/page1.html = www.domain.com/users/username/page1.html
    username.domain.com/page2.html = www.domain.com/users/username/page2.html
    username.domain.com/blah/something.html = http://www.domain.com/users/username...something.html

    ..& so on..

    Obviously I still want the subdomain "www" going to the main site & not to be re-written.

    Thanks for any help!

  • #2
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    First of all, do you have control over your server? can you modify/create your own virtual host containers?

    Second, do you have wild card DNS set up?

    Doing dynamic sub-domains is fairly strait forward once you have that set up.



    Eric
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Yes..... have got wildcard domains setup.

    can you modify/create your own virtual host containers?
    Yes.... have control over my server; but not quite sure what you mean by this?

  • #4
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    There are a probably a few ways this can be accomplished.
    This is the way I have done it in the past.

    I created 2 vhosts. the first serves my default site (www) and the other
    gets all wild card entries.

    From there, you can look at the SUBDOMAIN and do what ever you like with it.

    Here is a quick example I came up with.
    There is some obvious info missing like logs, error docs, etc.

    Code:
    <VirtualHost *>
    	DocumentRoot /var/www/htdocs/default
    	ServerName your.tld
    	ServerAlias www.your.tld
    </VirtualHost>
    	
    <VirtualHost *>
    	DocumentRoot /var/www/htdocs/dynamic
    	ServerName *.your.tld
    	ServerAlias *.your.tld
    
    	#this sets an environment variable for use with php
    	#php example: $_SERVER["SUBDOMAIN"];
    	RewriteEngine on
    	RewriteCond %{HTTP_HOST} ^(([a-zA-Z0-9_]+)\.)?your\.tld(:[\d]+)?$ [NC]
    	RewriteRule .* - [env=SUBDOMAIN:%2]
    </VirtualHost>
    Last edited by eak; 11-13-2007 at 10:20 PM.
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •