【问题标题】:htaccess to redirect all trafic from http to https but to also redirect to index.php which is hidden once on httpshtaccess 将所有流量从http重定向到https,但也重定向到在https上隐藏一次的index.php
【发布时间】:2016-01-22 04:48:24
【问题描述】:

我正在寻找一个可以执行以下操作的 .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 参数发送

谢谢

D

【问题讨论】:

  • 您的 Apache 版本是多少,您是否在使用代理或云服务?

标签: apache .htaccess http redirect https


【解决方案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]

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

【讨论】:

  • 结果:此网页存在重定向循环 ERR_TOO_MANY_REDIRECTS
  • RewriteCond %{HTTPS} off更改为RewriteCond %{HTTP:X-Forwarded-Proto} !https并重新测试
猜你喜欢
  • 2014-08-23
  • 1970-01-01
  • 2014-04-27
  • 1970-01-01
  • 2016-07-27
  • 2015-12-06
  • 1970-01-01
  • 1970-01-01
  • 2017-07-18
相关资源
最近更新 更多