NOT PERFECT YET

Using a single web hosting account to host multiple sites

NOT PERFECT YET

Postby softtoy » Fri Oct 06, 2006 5:34 am

richardk could you help?

I would like a little bit more in the last rule.

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]


I need to rewrite this:
random.tld -> /sub/random.tld/
anysub.random.tld -> /sub/anysub.random.tld/ if not exists -> /sub/random.tld/ if not exists -> root

Eg.
if not exist *.tld -> root
if not exist *.random.tld -> random.tld
if not exist *.sub.random.tld -> sub.random.tld
(not necessary to continue this forever meaning *.sub3.sub2.sub.random.tld -> sub3.sub2... etc., sub.random.tld level is enought mostly)
* is any string.

www.random.com or any other domain's www does not have to have special rules I think. They could be handled like other subs. (except maindomain?)

And also(possible?) rewrite maindomain.com(whatever one domain) to root. Prefer root, but if not root, then just not anything special for main, just like other domains /sub/maindomain.com.

Complicated or not?

EDIT: Lol I thought I was editing the last post but it was New thread
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm

Postby richardk » Fri Oct 06, 2006 10:52 am

Complicated. 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]

RewriteCond %{HTTP_HOST} !^(www\.)?[^\.]+\.[^\.]+$ [NC]
RewriteCond %{HTTP_HOST} ^(.*\.)?([^\.]+\.)([^\.]+\.[^\.]+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub/%3%{REQUEST_URI}/ -d
RewriteRule [^/]$ http://%2%3%{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]

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

not working yet

Postby softtoy » Fri Oct 06, 2006 4:43 pm

a.n.y.subdomain.random.tld works(->subdomain.random.tld), except the most important random.tld and www.random.tld, both goes always to root, should go to /sub/random.tld ? But - if possible - still let maindomain.com to go to root.

What would be correct?
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm

Postby richardk » Sat Oct 07, 2006 8:46 am

Try:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

# subdomains
RewriteCond %{HTTP_HOST} !^(www\.)?mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+\.[^\.]+\.[^\.]+)$ [NC]
RewriteCond %1:::%{REQUEST_URI} !^(.+):::/sub/\1(/.*)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub/%1/ -d
RewriteRule ^(.*)$ /sub/%1/$1 [QSA,L]

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

Postby softtoy » Sat Oct 07, 2006 10:48 am

does not catch subsubdomains at all even if there is dir named like it (a.n.y.sub.mydomain.com -->sub.mydomain.com, now goes always to root)

if random.tld dir exists all *.random.tld and also random.tld itself does error 500.

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

Postby richardk » Sat Oct 07, 2006 12:38 pm

My last attempt:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

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

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

Postby softtoy » Sat Oct 07, 2006 1:42 pm

It works \o/ :)))

My last wish:
--nothing, just figured it out by myself while this post was open--

Code: Select all
RewriteCond %{HTTP_HOST} ^(.*\.)([^\.]+\.[^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$ http://%2/$1 [R=301,L]

I added these after first block, and it seems to work: to catch any.thing.sub.domain.tld which was missing. (thanks to your comment for the block)

This kind of perfect virtualhosting code I have been looking for a long time!!!

Thanks and respect to u richardk :)
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm

adjustment

Postby softtoy » Mon Oct 09, 2006 6:22 am

Little bit adjustment:
Is it able to add to this current code option to eg. show basic directory listing like:"Index of /dir", instead of: "Index of /sub/sub.domain.com/dir". I was testing and some code did that simple "Index of /dir", but then there was something else missing(eg.https).

Current code to modify:
Code: Select all
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*\.)?([^\.]+\.)([^\.]+\.[^\.]+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub/%2%3%{REQUEST_URI}/ -d [OR]
RewriteCond %{DOCUMENT_ROOT}/sub/%3%{REQUEST_URI}/ -d
RewriteCond %{SERVER_PORT} !^443$
RewriteRule [^/]$ http://%1%2%3%{REQUEST_URI}/ [R=301,L]

RewriteCond %{HTTP_HOST} ^(.*\.)([^\.]+\.[^\.]+\.[^\.]+)$ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ http://%2/$1 [R=301,L]


RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*\.)?([^\.]+\.)([^\.]+\.[^\.]+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub/%2%3%{REQUEST_URI}/ -d [OR]
RewriteCond %{DOCUMENT_ROOT}/sub/%3%{REQUEST_URI}/ -d
RewriteCond %{SERVER_PORT} !^80$
RewriteRule [^/]$ https://%1%2%3%{REQUEST_URI}/ [R=301,L]

RewriteCond %{HTTP_HOST} ^(.*\.)([^\.]+\.[^\.]+\.[^\.]+)$ [NC]
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^(.*)$ https://%2/$1 [R=301,L]


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

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


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

Postby richardk » Mon Oct 09, 2006 10:04 am

You can't change the path in the directory listings with mod_rewrite. You'd probably have to write your directory listing module.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

keep address in the address bar

Postby softtoy » Fri Oct 20, 2006 11:28 am

Could you tell me one more small thing:

Now this code does:

sub3.sub2.sub1.domain.com --> sub1.domain.com
AND it will change the address in the address bar to --> sub1.domain.com

I would like this:

sub3.sub2.sub1.domain.com --> sub1.domain.com
AND KEEP address in the address bar --> sub3.sub2.sub1.domain.com

What I need to modify?
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 45 guests

cron