regex - Apache Redirect setting https to http and matching & not matching -
i confusing redirect setting apache. looks simple can’t figure out…
under http access
if carts/ , events/* need redirect https
i adding setting in sites-enabled/default-http.conf
<ifmodule mod_rewrite.c> rewriteengine on rewritecond %{request_uri} ^/carts/ [or] rewritecond %{request_uri} ^/events/* rewritecond %{https} off rewriterule ^(.*)$ https://%{http_host}%{request_uri} [r,l] </ifmodule>
under https access
if not carts/ , events/* need redirect http
i adding setting in sites-enabled/default-https.conf
<ifmodule mod_rewrite.c> rewriteengine on rewritecond %{request_uri} !(^/carts/) [or] rewritecond %{request_uri} !(^/events/*) rewriterule ^(.*)$ http://%{http_host}%{request_uri} [r,l] </ifmodule>
the problem this
http working https not work.
https://test.com/test should redirect http://test.com/test
first of avoid restart of apache enable .htaccess (if not enabled already) use these rules in site root .htaccess:
rewriteengine on rewritecond %{the_request} /(carts|events)/ [nc] rewritecond %{https} off rewriterule ^ https://%{http_host}%{request_uri} [l,ne,r=302] rewritecond %{the_request} !/(carts|events)/ [nc] rewritecond %{https} on rewriterule ^ http://%{http_host}%{request_uri} [l,ne,r=302]
test in new browser avoid old browser cache. , preferable test in chrome dev tool see redirects you're getting.
Comments
Post a Comment