???.domain.com or www.???.domain.com -> ww.domain.com/???

Using a single web hosting account to host multiple sites

???.domain.com or www.???.domain.com -> ww.domain.com/???

Postby ledruide » Thu Mar 10, 2005 7:24 am

Hello all,

I would like to transform an URL like :

http://sub.domain.com or http://www.sub.domain.com
into something like http://www.domain.com/sub/

but sub must not be certain values like : mail, www or images and some others...

I wanted to try this kind of rule but before trying I'd like to know if it is correct or not :confused: , can you tell me if you think it seems ok or if there is any problem ?

RewriteEngine on

# First rule block to deal with the http://www.sub.domain.com
RewriteCond %{HTTP_HOST} !^www\.www\.domain\.com$
RewriteCond %{HTTP_HOST} !^www\.mail\.domain\.com$
RewriteCond %{HTTP_HOST} !^www\.images\.domain\.com$
RewriteCond %{HTTP_HOST} ^(www\.*)\.domain\.com$

# Second rule to deal with the http://sub.domain.com
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} !^mail\.domain\.com$
RewriteCond %{HTTP_HOST} !^images\.domain\.com$
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$

# ok rewrite now
RewriteRule (.*) http://www.domain.com/%1$1 [P]


Thanx a lot
LeDruide
ledruide
 
Posts: 3
Joined: Thu Mar 10, 2005 6:34 am
Location: Paris, France

Postby Caterham » Thu Mar 10, 2005 8:37 am

Better use for .htaccess
Code: Select all
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?(www|mail|images)\.domain\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain\.com
# ok rewrite now
RewriteRule ^(.*) http://www.domain.com/%2/$1 [P,L]


or per-server context (parts of httpd.conf)

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?(www|mail|images)\.domain\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain\.com
# ok rewrite now
RewriteRule ^/(.*) http://www.domain.com/%2/$1 [P,L]
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Postby ledruide » Fri Mar 11, 2005 2:06 am

Thanks a lot this looks really simple, I'm going to dive deeper into regular expressions... :o

I'll try that tonight (I don't have the access right now...).

Just another simple question : what do you think is better : .htaccess or httpd.conf for this configuration ?

Thanks again :D
ledruide
 
Posts: 3
Joined: Thu Mar 10, 2005 6:34 am
Location: Paris, France

Postby Caterham » Fri Mar 11, 2005 5:04 am

definitely in httpd.conf (outside of <Directory> or <Location>, so add this in the main server Config section (outside any container) or in a <Virtualhost>-Container)
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Postby ledruide » Fri Mar 11, 2005 1:20 pm

Thanks again !

May I ask just a little more ? :-? :biggrin:

What would be the rewriting rule if I have multiples domain on that same request would that rule be correct ? :confused:
I don't know what to write instead of the %3 wich is probably incorrect ?

Code: Select all
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?(www|mail|images)\.?(domain1|otherdomain|thirddomain)\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.?(domain1|otherdomain|thirddomain)\.com
# ok rewrite now
RewriteRule ^/(.*) http://www.%3.com/%2/$1 [P,L]


Thank you again, this forum is full of great ressources !!
ledruide
 
Posts: 3
Joined: Thu Mar 10, 2005 6:34 am
Location: Paris, France

Postby Caterham » Fri Mar 11, 2005 3:10 pm

I don't know what to write instead of the %3 wich is probably incorrect ?
No, this is correct :)
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

subdomain rewrite vs. ns wildcards

Postby eof » Thu Dec 15, 2005 11:50 am

Code: Select all
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?(www|mail|images)\.domain\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain\.com
# ok rewrite now
RewriteRule ^(.*) http://www.domain.com/%2/$1 [P,L]


just some lame questions:
- where should I put htaccess with these rules? main domain? I don't want to create ANY directory for new subdomains, as I am going to provide mass blogging website. I need a virtual subdomain rewriting rule I could put "somwhere" to rewrite all the subdomains into domain/?foobar=subdomain. Now, nothing seems to work for me - I get redirected to default apache html - with or withour these rules :/ Rewriting works fine for typical redirects like domain.tld/foobar -> domain.tld/?foobar=1 and so on. Any clues?

- do I need a *.domain.com as domain alias in httpd.conf, if so - any way to override this?

thanx a lot for the patience. If I was too blind to notice these questions answered in some topic, would appreciate the link! :)

rgrds

eof

sorry for the new topic, but this script really sux :/
eof
 
Posts: 1
Joined: Thu Dec 15, 2005 11:38 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 46 guests

cron