NOT PERFECT YET

Using a single web hosting account to host multiple sites

Postby richardk » Fri Oct 20, 2006 11:46 am

Try:
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} !^(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]

# 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 » Fri Oct 20, 2006 11:53 am

Everything except domain.com and www.domain.com does error 500.
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm

Postby richardk » Fri Oct 20, 2006 12:50 pm

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
RewriteCond %1%2%3:%{SERVER_PORT}:s ^(.+):443:(s)$ [OR]
RewriteCond %1%2%3:%{SERVER_PORT}   ^(.+):80$
RewriteRule [^/]$ http%2://%1%{REQUEST_URI}/ [R=301,L]

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

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


The mod_dir fix part may not work, then you'll need to replace it with:
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} !^(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]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby softtoy » Fri Oct 20, 2006 2:55 pm

Works! (longer mod_dir..)

One thing, can this be fixed?

E.g:
http://a.a.sub.domain.com/sub/sub.domain.com/

It goes
htdocs/sub/sub.domain.com/
but it should go
htdocs/sub/sub.domain.com/sub/sub.domain.com/

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

Postby richardk » Fri Oct 20, 2006 3:10 pm

I think that might be because of the mod_dir fix that didn't work. Clear your browser's cache and try again. If that's not it, explain exactly what you're doing (what did you type in the address bar/what is the exact link), what result you're getting and what you expected.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby softtoy » Fri Oct 20, 2006 4:13 pm

This rewrite rule is inside <directory> -section in httpd.conf:
Code: Select all
# 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
RewriteCond %{SERVER_PORT} !^443$
RewriteRule [^/]$ http://%1%2%3%{REQUEST_URI}/ [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} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*\.)?([^\.]+\.[^\.]+\.[^\.]+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub/%2/ -d
RewriteRule !^sub(/.*)?$ /sub/%2%{REQUEST_URI} [QSA,L]

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


E.g. I'll go to:
http://a.a.a.a.domain.com/sub/mydom.net/

If /htdocs/sub/mydom.net/ exists --> above address will lead to mydom.net site(/htdocs/sub/mydom.net/) which is wrong.

This address should show 404 mostly because there is no /sub/mydom.net/ dir inside the /htdocs/sub/a.domain.com/


E.g. this address: http://a.a.a.a.domain.com/sub/
It does not check/goto "sub" dir inside the /htdocs/sub/a.domain.com/
It will lead to /htdocs/sub/ or http://domain.com/sub/ which is wrong.


Original address typed will stay in the address bar always, which is correct.

Everything works except when going to: http://asd.domain.com/sub, then it will map sub incorrectly.

?


(this rule seems not to work in htaccess inside htdocs, in httpd.conf it will, which is fine and preferable too)
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm

Postby richardk » Sat Oct 21, 2006 6:49 am

Replace the last two blcoks with:
Code: Select all
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]

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 21, 2006 11:16 am

Maybe better. But still mapping something incorrectly..:(


Examples:


Does not work

There is rewrite rule in one subdomain's htaccess file like this
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^([a-zA-Z0-9\-_'!:;]+)$ ?var=$1

which works with subs this_dir_exists.domain.com/itwillcatchthis
itwillcatchthis is catched when there is no trailing slash after it nor dir named like it(correct). But you can't catch this_dir_exists.domain.com/sub with this moddirfix rule. It will go to /sub/ directory instead(does 404), seems to "override" itwillcatchthis rule.

http://a.a.a.a.a.domain.com/sub/a.domain.com/ ("a.domain.com" dir exists)
This should give error 404 but it won't. It will go to /htdocs/sub/a.domain.com/ or http://a.domain.com

http://aaaaaa.domain.com/sub/this_dir_E ... omain.com/ ("aaaaaa.domain.com" dir does NOT exists)
This will go to this_dir_EXISTS.domain.com, wrong.

http://dir_that_exists.domain.com/sub/a.domain.com/ (dir "a.domain.com" exists)
Goes to /htdocs/sub/a.domain.com/ or http://a.domain.com


Works

http://dir_that_EXISTS.domain.com/sub/t ... omain.com/
Does 404. (This goes still wrong http://dir_that_exists.domain.com/sub/a.domain.com/ "a.domain.com" dir exists)


?
Last edited by softtoy on Sat Oct 21, 2006 11:44 am, edited 2 times in total.
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm

Postby richardk » Sat Oct 21, 2006 11:35 am

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

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


But you should just use something more complicated than "sub" (like _s-u-b), something that you're not going to use anywhere else.

No more edits to this. If you need it changing you'll have to learn about mod_rewrite. To be honest i think you should be using <VirtualHost>s anyway.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby softtoy » Sat Oct 21, 2006 12:14 pm

Still there was some problems in this rule.. Maybe I'll use the original longest one right now..

I was thinking also that maybe I should use something mod_vd etc. But if this rule just would work it would be perfect and nothing more crap mod_vd's etc, would not be needed. Vhosts, I'll use them in some situations maybe and when I got vhost mysql module working. But still in this "simple" /sub/ redirect it would be the best way to simply do rewrite.

Thanks alot for your help! I'll stop bugging you and try to figure it out by myself, maybe :)

But if you'll figure out fully working transparent vhosting rewrite rule(you know what I mean) I would like if you could tell it to me. Best one of these rules here works still very good, but missing something, donno could I figure it out by myself..
softtoy
 
Posts: 26
Joined: Mon Jun 12, 2006 9:45 pm

Previous

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 19 guests

cron