简体   繁体   中英

Problems using apache rewriterules

Hi here are my rewrite conditions:

LogLevel alert rewrite:trace3
RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^/(myapp)/ - [E=MY_URL:1]

RewriteCond %{ENV:MY_URL} 1
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}

I'm trying to redirect everything that goes to http://www.example.com/myapp/ to https://www.example.com/myapp/ but it seems that I'm getting an infinite loop, I tried putting 2 conditions so if HTTPS was on it shouldn't redirect, any help would be appreciated, thanks!

UPDATE 1 i change it to the following

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/myapp
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]

I don't understand the part [R=301], but it still giving me the ERR_TOO_MANY_REDIRECTS error

Ok i figure it out thanks to a friend and this link ,

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} ^/myapp
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

i dont know why RewriteCond %{HTTPS} off doesnt work here on my rules (apache 2.4), so i used %{HTTP:X-Forwarded-Proto} !https instead, works like a charm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM