强制https在不使用.htaccess的子文件夹上

时间:2017-02-24 11:37:06

标签: apache .htaccess

当我手动输入https://www.domain.com.br/app/时,页面会正确加载。但是当我使用以下代码添加.htaccess文件时:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} app 
RewriteRule ^(.*)$ https://domain.com.br/app/$1 [R,L]

浏览器说我的域无效,并显示此错误:ERR_TOO_MANY_REDIRECTS

1 个答案:

答案 0 :(得分:1)

我认为你创建地址 https://domain.com.br/app/app/,这可以在另一个地方捕获并返回开始。单独的规则应该是

RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

另一件事是基于protovol制造decission,而不是端口。完整的代码是:

RewriteEngine On
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{REQUEST_URI} ^/app(/.*)?
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]