Modify this a little bit please.

Using a single web hosting account to host multiple sites

Modify this a little bit please.

Postby softtoy » Sat Sep 23, 2006 5:08 pm

Code: Select all
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST}  ^(.*\.)?([^\.]+)\.domain\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub/%2/ -d
RewriteRule !^sub(/.*)?$ /sub/%2%{REQUEST_URI} [QSA,L]

RewriteCond %{ENV:REDIRECT_STATcom} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST}  ^(.*\.)?([^\.]+)\.domain\.com$ [NC]
RewriteCond %2---%{REQUEST_URI} ^([^\.]+)---/sub/\1(/.*)?$
RewriteRule ^sub(/.*)?$ http://%1.domain\.com%2 [R=301,L]


This makes:
something.domain.com -> /sub/something/

Can anyone tell me how to modify this to do:
something.domain.com -> /sub/something.domain.com/
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm

Postby richardk » Sun Sep 24, 2006 5:55 am

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# mod_dir fix
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*\.)?([^\.]+\.domain\.com)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub/%{REQUEST_URI}/ -d
RewriteRule [^/]$ http://%2%{REQUEST_URI}/ [R=301,L]

# strip sub subdomains
RewriteCond %{HTTP_HOST} ^(.*\.)([^\.]+\.domain\.com)$ [NC]
RewriteRule ^(.*)$ http://%2/$1 [R=301,L]

# sub.domain.com/abc --> /sub/sub.domain.com/abc
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+\.domain\.com)$ [NC]
RewriteCond %2:::%{REQUEST_URI} !^(.+):::/sub/\1(/.*)?$ [NC]
RewriteRule ^(.*)$ /sub/%2/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

?

Postby softtoy » Mon Sep 25, 2006 4:30 pm

that one gives an internal error and if I edit last line to this code
Code: Select all
RewriteRule ^(.*)$ /sub/%1 [QSA,L]

url then shows like > http://sub.domain.com/sub/sub.domain.com/

how about when I also need to do this :/
something.domain2.com -> /sub/something.domain2.com/
something.domain123.net -> /sub/something.domain123.net/
something.anything.org -> /sub/something.anything.org/

?
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm

Postby richardk » Tue Sep 26, 2006 7:05 am

Try:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# mod_dir fix
RewriteCond %{HTTP_HOST} !^(www\.)?[^\.]+\.[^\.]+$ [NC]
RewriteCond %{HTTP_HOST} ^(.*\.)?([^\.]+\.[^\.]+\.[^\.]+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub/%2%{REQUEST_URI}/ -d
RewriteRule [^/]$ http://%2%{REQUEST_URI}/ [R=301,L]

# strip sub subdomains
RewriteCond %{HTTP_HOST} ^(.*\.)([^\.]+\.[^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$ http://%2/$1 [R=301,L]

# sub.domain.com/abc --> /sub/sub.domain.com/abc
RewriteCond %{HTTP_HOST} !^(www\.)?[^\.]+\.[^\.]+$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+\.[^\.]+\.[^\.]+)$ [NC]
RewriteCond %1:::%{REQUEST_URI} !^(.+):::/sub/\1(/.*)?$ [NC]
RewriteRule ^(.*)$ /sub/%1/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

thanks

Postby softtoy » Tue Sep 26, 2006 10:23 am

It works! You are guru! Thank god you exist! o/

One more question:
Seems it does not check dir existence correctly? "-d" thing. Because I get 404, it should go to e.g. domain.com if no dir found.

How's that?
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm

Postby richardk » Tue Sep 26, 2006 12:35 pm

The -d part adds missing trailing slashes to real directories to stop mod_dir changing it to the domain.com/sub/sub.domain.com/abc URL.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby softtoy » Tue Sep 26, 2006 3:22 pm

Ok.

Someone said to me this:
the "-d" checks for the existence of a directory


Anyway, do you know how could this be fixed? Your code works perfectly except if I type idsahsgh.domain.com and there is no such dir in sub folder, how to check this? It would then go e.g. domain.com instead of showing "error 404 /sub/idsahsgh.domain.com not found"

Do you know?

Ps.
Original code(this thread's 1st post) goes domain.com if there is no such directory found. How to add it to this last one?
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm

Postby richardk » Wed Sep 27, 2006 6:09 am

It is checking for the existance of a directory, but only if there's a missing trailing slash. It's working with the other RewriteConds and the RewriteRule to preform the task. It's not part of the "# sub.domain.com/abc --> /sub/sub.domain.com/abc" section.

You didn't say you wanted it changed:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# mod_dir fix
RewriteCond %{HTTP_HOST} !^(www\.)?[^\.]+\.[^\.]+$ [NC]
RewriteCond %{HTTP_HOST} ^(.*\.)?([^\.]+\.[^\.]+\.[^\.]+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub/%2%{REQUEST_URI}/ -d
RewriteRule [^/]$ http://%2%{REQUEST_URI}/ [R=301,L]

# strip sub subdomains
RewriteCond %{HTTP_HOST} ^(.*\.)([^\.]+\.[^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$ http://%2/$1 [R=301,L]

# sub.domain.com/abc --> /sub/sub.domain.com/abc
RewriteCond %{HTTP_HOST} !^(www\.)?[^\.]+\.[^\.]+$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+\.[^\.]+\.[^\.]+)$ [NC]
RewriteCond %1:::%{REQUEST_URI} !^(.+):::/sub/\1(/.*)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub/%1/ -d
RewriteRule ^(.*)$ /sub/%1/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby softtoy » Wed Sep 27, 2006 10:13 am

Thanks rich !!!!
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 46 guests

cron