【问题标题】:Https to http redirect using htaccess for a single PHP file使用 htaccess 对单个 PHP 文件进行 Https 到 http 重定向
【发布时间】:2018-09-15 17:12:11
【问题描述】:

我正在尝试将https://demo.aurazoscript.com/surf.php?id=15 重定向到http://demo.aurazoscript.com/surf.php?id=15。我在 .htaccess 中尝试了以下操作,但这不起作用。它关闭了我不想要的整个网站的强制 HTTPS 重定向。我只希望为该单页 surf.php 关闭它。

我在 .htaccess 中尝试过

# FORCE HTTPS
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} \/(surf.php)
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

# DISABLE HTTPS
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !\/(surf.php) [NC]
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

我正在使用来自 CloudFlare 的灵活 SSL。

【问题讨论】:

标签: apache .htaccess http ssl https


【解决方案1】:

我认为你这样做相反,在RewriteEngine On之后的.htaccess文件的开头试试这个:

RewriteCond %{HTTP:X-Forwarded-Proto} https [OR]
RewriteCond %{HTTPS} on
RewriteRule ^surf\.php   http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTPS} off
RewriteRule !^surf\.php  https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

注意:清除浏览器缓存然后测试。

【讨论】:

  • 试过了。不工作。您可以访问该网站并检查。此代码仍在我的 .htaccess 文件中。
  • @AppleBux 你清除浏览器缓存了吗?我有什么改变吗?让我知道哪个请求无效,哪个有效
  • 等一下。在RewriteEngine On 之后粘贴您的代码后,浏览器退出并返回demo.aurazoscript.com redirected you too many times. 这意味着您的代码有一些错误。它不工作。请检查。
  • @AppleBux 还有其他规则吗?
猜你喜欢
  • 1970-01-01
  • 2019-06-25
  • 1970-01-01
  • 1970-01-01
  • 2019-03-18
  • 2012-10-11
  • 2015-11-10
  • 2016-06-28
  • 2018-08-31
相关资源
最近更新 更多