regex - Redirect non-www to www except subdomains by .htaccess -


there few questions this, question little different

redirect non-www www in .htaccess

force non www www in htaccess

redirect non-www www urls

i want redirect non-www version of website www, should not in way effect subdomains, so

www.example.com => www.example.com example.com => www.example.com sub1.example.com => sub1.example.com sub2.example.com => sub2.example.com 

this not work, cause not behave in case of subdomains

rewritecond %{http_host} !^www\. rewriterule ^(.*)$ https://www.%{http_host}/$1 [r=301,l] 

this solution works fine

rewritecond %{http_host} ^example.com$ rewriterule (.*) https://www.example.com/$1 [r=301,l]  

however, important thing not want hardcode domain name in htacess. how (if possible) have above mentioned redirections general case - without mentioned exact domain name ?

thanks

you can use rule:

rewritecond %{http_host} ^[^.]+\.com(\.au)?$ [nc] rewriterule ^(.*)$ https://www.%{http_host}/$1 [r=301,l] 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -