apache - How do i force www subdomain on both https and http -


for whatever reason can't seem right, i've looked @ many examples on here , apache's website. i'm trying force www.domain.com instead of domain.com on either http or https not trying force https on http.

the following code seems work https connections http not redirect www.

rewriteengine on rewritecond %{https} on rewritecond %{http_host} !^www\.domain\.com$ [nc] rewriterule ^ https://www.domain.com%{request_uri} [r=301]  rewriteengine on rewritecond %{https} off rewritecond %{http_host} !^www\.domain\.com$ [nc] rewriterule ^ http://www.domain.com%{request_uri} [r=301] 

  1. you don't need second rewriteengine directive. may or may not causing parse issue making second set of rules not work. test whether case, try switching order of 2 blocks have.
  2. it's practice use l modify requests last. so, change [r=301] [r=301,l] both times appears.
  3. largely matter of style, consider changing rewriterule directives (using http or https appropriate):

    rewriterule ^(.*)$ http://www.domain.com$1 [r=301,l,qsa]


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -