Username Sub Domains

Using a single web hosting account to host multiple sites

Postby MxH » Mon Nov 03, 2008 2:54 am

Hello Everyone.
I'm beginner with mod_rewrite :s, I really ned help
I rewrite :

This: http://www.yourdomain.com/profile.php?user=username
To: http://username.yourdomain.com

This: http://www.yourdomain.com/albums.php?user=username
To: http://username.yourdomain.com/albums/

This: http://www.yourdomain.com/album.php?user=username&album_id=id1
To: http://username.yourdomain.com/albums/id1/

This: http://www.yourdomain.com/album_file.php?user=username&album_id=id1&media_id=id2
To: http://username.yourdomain.com/albums/id1/id2/

This: http://www.yourdomain.com/blog.php?user=username
To: http://username.yourdomain.com/blog/

This: http://www.yourdomain.com/blog_entry.php?user=username&blogentry_id=id1
To: http://username.yourdomain.com/blog/id1/

This: http://www.yourdomain.com/content.php?page=username
To: http://username.yourdomain.com/page/

This: http://www.yourdomain.com/polls.php?user=username
To: http://username.yourdomain.com/Polls/

This: http://www.yourdomain.com/poll.php?user=username&poll_id=id1
To: http://username.yourdomain.com/poll/id1/

This: http://www.yourdomain.com/games.php?user=username
To: http://username.yourdomain.com/games/

This: http://www.yourdomain.com/game.php?user=username&game_id=id1
To: http://username.yourdomain.com/games/id1

This: http://www.yourdomain.com/game_file.php?user=username&game_id=id1&game_media_id=id2
To: http://username.yourdomain.com/games/id1/id2

This: http://www.yourdomain.com/videos.php?user=username
To: http://username.yourdomain.com/videos/

This: http://www.yourdomain.com/video.php?user=username&video_id=id1
To: http://username.yourdomain.com/videos/id1

This: http://www.yourdomain.com/video_file.php?user=username&video_id=id1&video_media_id=id2
To: http://username.yourdomain.com/videos/id1/id2

This: http://www.yourdomain.com/mf_gifts_user.php?user=username
To: http://username.yourdomain.com/gifs/

Thanks...
MxH
 
Posts: 3
Joined: Mon Nov 03, 2008 2:13 am

Postby richardk » Mon Nov 03, 2008 12:38 pm

The sub domains will need DNS. The server will need to be configured to send all sub domain requests to the same document root (the directory containing these files).

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule .* - [L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^$ / [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^(albums|blog|polls|videos|games)/?$ /$1.php?user=%1 [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^(albums|game|video)s/([^/]+)/?$ /$1.php?user=%1&$1_id=$2 [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^(game|video)s/([^/]+)/([^/]+)/?$ /$1_file.php?user=%1&$1_id=$2&$1_media_id=$3 [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^gifs/?$ /mf_gifts_user.php?user=%1 [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^page/?$ /content.php?page=%1 [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^albums/([^/]+)/([^/]+)/?$ /album_file.php?user=%1&album_id=$1&media_id=$2 [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^blog/([^/]+)/?$ /blog_entry.php?user=%1&blogentry_id=$1 [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^poll/([^/]+)/?$ /poll.php?user=%1&poll_id=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby MxH » Fri Nov 07, 2008 3:51 am

Well, this doesn't work :(
Any way.
How can we do this :
If someone put this url http://anything.domaine.com
he is redirected to http://www.domaine.com/profile.php?user=anything

except http://www.domaine.com/ this don't have to be redirected

Thanks for you help :)
MxH
 
Posts: 3
Joined: Mon Nov 03, 2008 2:13 am

Postby richardk » Fri Nov 07, 2008 12:04 pm

Well, this doesn't work

You'll have to be more specific.

What happens?
What happens without the mod_rewrite?
Do you have DNS for the sub domains?
What files so you see when you go to the sub domains? Is it always the same files? Is it the same as your main domain?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule .* - [L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^$ /profile.php?user=%1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby MxH » Fri Nov 07, 2008 12:35 pm

Don't have DNS for subdomain
MxH
 
Posts: 3
Joined: Mon Nov 03, 2008 2:13 am

Postby richardk » Sun Nov 09, 2008 11:39 am

Then you need to create some DNS records for the sub domains. You might want to use Wildcard DNS.

The server also needs to be configured to send all the sub domains to the same document root.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 20 guests

cron