Go Back   CodingForums.com > :: Client side development > General web building

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2007, 08:52 PM   PM User | #1
cyphix
Regular Coder

 
Join Date: Apr 2004
Posts: 682
Thanks: 24
Thanked 1 Time in 1 Post
cyphix is an unknown quantity at this point
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!
cyphix is offline   Reply With Quote
Old 11-13-2007, 10:00 PM   PM User | #2
eak
Regular Coder

 
eak's Avatar
 
Join Date: Jun 2002
Location: Nashville, TN
Posts: 354
Thanks: 0
Thanked 26 Times in 26 Posts
eak is on a distinguished road
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."
eak is offline   Reply With Quote
Old 11-13-2007, 10:07 PM   PM User | #3
cyphix
Regular Coder

 
Join Date: Apr 2004
Posts: 682
Thanks: 24
Thanked 1 Time in 1 Post
cyphix is an unknown quantity at this point
Yes..... have got wildcard domains setup.

Quote:
can you modify/create your own virtual host containers?
Yes.... have control over my server; but not quite sure what you mean by this?
cyphix is offline   Reply With Quote
Old 11-13-2007, 10:15 PM   PM User | #4
eak
Regular Coder

 
eak's Avatar
 
Join Date: Jun 2002
Location: Nashville, TN
Posts: 354
Thanks: 0
Thanked 26 Times in 26 Posts
eak is on a distinguished road
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>
__________________
eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."

Last edited by eak; 11-13-2007 at 10:20 PM..
eak is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:53 PM.


Advertisement
Log in to turn off these ads.