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