htaccess将所有流量从http重定向到https,但也重定向到在https上隐藏一次的index.php

时间:2016-01-22 04:48:25

标签: apache .htaccess http redirect https

我正在寻找一个可以执行以下操作的.htaccess文件,我设法让每个功能单独工作但不能一起工作。

要求号1: 所有HTTP流量都重定向到HTTPS

要求号2: 所有HTTPS URL都定向到index.php?url_params =

我要么在request_uri上以无限循环结束,要么最终出现服务器错误:

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTPS} off
#RewriteCond %{HTTP:X-Forwarded-Proto} = http
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ./index.php?url_path=$1 [L,NC,QSA]

因此,如果有人输入" http://www.example.com/page1"它会重定向到" https://www.example.com/page1"然后" https://www.example.com/page1"被发送到index.php,page1作为url param发送

由于

d

1 个答案:

答案 0 :(得分:1)

请尝试以下规则:

Options +FollowSymlinks
RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url_path=$1 [L,QSA]

在测试此更改之前清除浏览器缓存。