apache - .htaccess how to handle dynamic sub-domain redirect to https and no sub-domain to www -


i have htaccess file gitignored , while upgrading laravel 5.2 deleted old 1 on server. spent hours piecing , i'm struggling recreate it.

i need

http://domain.com   

or

https://domain.com 

to goto

https://www.domain.com  

and other wildcard sub-domains such as:

http://myname.domain.com  

to goto

https://myname.domain.com  

so far have this:

rewritecond %{https} off rewriterule .* https://%{http_host}%{request_uri} [l,r=301] rewritecond %{http_host} !^www\. rewriterule .* https://www.%{http_host}%{request_uri} [l,r=301] 

to redirect subdomains , main domain https, can use:

rewriteengine on  #--redirect subdomain https--# rewritecond %{http_host} ^((?!www\.).+)\.domain.com$ [nc] rewritecond %{https} off rewriterule ^ https://%{http_host}%{request_uri} [nc,r,l]  #--redirect maindomain https --# rewritecond %{http_host} ^(www\.)?domain.com$ [nc] rewritecond %{https} off rewriterule ^ https://www.domain.com%{request_uri} [nc,r,l] #--redirect non-www www on ssl--# rewritecond %{http_host} !^www\.example\.com$ rewritecond %{https} on rewriterule ^ https://www.example.com%{request_uri} [nc,l,r] 

change r r=301 when sure redirect working fine.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -