regex - How to force www to replace subdomain in a generic way -
i using shared codebase support several domains, , want force use of www subdomain in .htaccess, replacing other subdomain provided without otherwise altering http_host.
i've read several solutions on how force www when subdomain not provided (e.g. example.com becomes www.example.com) , how add www beginning of http_host (e.g. test.example.com becomes www.test.example.com). have not found how replace subdomain (or lack thereof) www while keeping first , second level domains intact, whatever might be.
i need generic rule make of following rewrites (as 301s) without having write rules every tld , every possible subdomain:
- example.com => www.example.com
- test.example.com => www.example.com
- example.ca => www.example.ca
- blog.example.ca => www.example.ca
- example.be => www.example.be
- users.example.be => www.example.be
- example.co.uk => www.example.co.uk
- users.example.co.uk => www.example.co.uk
you can use rule cases:
rewriteengine on rewritecond %{http_host} !^www\. [nc] rewritecond %{http_host} ^(?:[^.]+\.)?(example\..+)$ [nc] rewriterule ^ http://www.%1%{request_uri} [r=301,l,ne]
Comments
Post a Comment