Static And Wildcard sub domains

Using a single web hosting account to host multiple sites

Static And Wildcard sub domains

Postby ChazUK » Sat Mar 08, 2008 5:43 pm

Hi, sorry if this question has been asked before, I searched through the boards to see if it had been answered already, but I couldn't find anything about using both types.

I would like to have it setup so that users can have their own sub domain of their choice ie username.domain.com, but still keep certain sub domains for site functions, such as my.domain.com for all of the users account preferences and stuff.

Some examples of links I would like to use are

http://www.domain.com/login/
http://www.domain.com/logout/
http://www.domain.com/join/
http://www.domain.com/browse/
http://www.domain.com/shop/

http://my.domain.com/
http://my.domain.com/profile/
http://my.domain.com/account/

http://username.domain.com/
http://username.domain.com/blog/
http://username.domain.com/gallery/
http://username.domain.com/videos/


So far my .htaccess file looks like this
Code: Select all
Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]

## Regular Site Rewrites
RewriteRule ^login/?$ /login.php
RewriteRule ^logout/?$ /logout.php
RewriteRule ^join/?$ /join.php

## Custom User Sub Domain
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9]+)\.domain\.com$ [NC]
RewriteRule ^$ /view_profile.php?user_url=%2 [NC,L]

My knowledge is intermediate.

If there is anything else that you need to know, I'll be happy to answer.

Thanks
ChazUK
 
Posts: 4
Joined: Sat Mar 08, 2008 5:30 pm

Postby richardk » Mon Mar 10, 2008 3:53 pm

So you want the "Custom User Sub Domain" section to ignore the my sub domain? Then replace
Code: Select all
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]

with
Code: Select all
RewriteCond %{HTTP_HOST} !^(www|my)\.domain\.com$ [NC]


Or do you need it to do something special with the my sub domain as well?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ChazUK » Mon Mar 10, 2008 3:55 pm

Well I'd like for it to have it's own set of rules, like /profile/ redirecting to edit_profile.php and /account/ to edit_account.php

Also the same with the wildcard subdomains.
Thanks for that worked a treat.
ChazUK
 
Posts: 4
Joined: Sat Mar 08, 2008 5:30 pm

Postby richardk » Mon Mar 10, 2008 4:18 pm

Then you need something like
Code: Select all
Options +FollowSymLinks +Indexes

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]

## Regular Site Rewrites
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(login|logout|join)/?$ /$1.php [QSA,L]

## my.example.com rules
RewriteCond %{HTTP_HOST} ^my\.example\.com4 [NC]
RewriteRule ^(profile|account)/?$ /edit_$1.php [QSA,L]

## Custom User Sub Domain
RewriteCond %{HTTP_HOST} !^(www|my)\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9]+)\.domain\.com$ [NC]
RewriteRule ^$ /view_profile.php?user_url=%2 [NC,L]

RewriteCond %{HTTP_HOST} !^(www|my)\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9]+)\.domain\.com$ [NC]
RewriteRule ^(some|random|stuff) /more+stuff [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ChazUK » Mon Mar 10, 2008 4:26 pm

That is great, but what about if the rules for the Custom User Sub Domain get a bit more complex?

For example username.domain.com/album/icons/dock-icon-12345

As far as I know you can't list multiple rules under a condition? would I just have to write out the conditions again?

Thanks
ChazUK
 
Posts: 4
Joined: Sat Mar 08, 2008 5:30 pm

Postby richardk » Mon Mar 10, 2008 4:29 pm

Yes, you have to repeat the conditions.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ChazUK » Mon Mar 10, 2008 4:35 pm

Thanks so much, you've been a great help :)
ChazUK
 
Posts: 4
Joined: Sat Mar 08, 2008 5:30 pm


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 20 guests

cron