.htaccess - htaccess non www to www and remove subdomain www -
so i've got following rewrite code in htaccess
rewriteengine on rewritecond %{http_host} ^[^.]+\.[^.]+$ rewriterule ^(.*)$ http://www.%{http_host}/$1 [l,r=301] // rewriteengine on rewritecond %{http_host} ^www\.([^\.]*)\.domain\.com$ [nc] rewriterule (.*) http://%1.domain.com$1 [r=301,l]
works perfect redirecting non-www www domains.
i've got subdomain, lets call 'sub.domain.com
' works find. if goto www.sub.domain.com
, redirecting 'sub.domain.com/sub/
' having idea why?
none of rules have in question routes requests subdomain's folder. /sub/
should never there if wasn't in request.
that said, of redirect rules need come before routing rules. routing rules being stuff internally routes requests other uri's, example:
rewritecond %{http_host} ([^\.]*)\.domain\.com$ [nc] rewriterule (.*) /%1/$1 [l]
that rule internall routes folder named same thing subdomain. if rule before redirect, both rules applied , redirected uri becomes /sub/
. need routing rules placed after redirect rules, e.g. rules have http://
or r
flag.
Comments
Post a Comment