简体   繁体   English

使用mod_rewrite在某些页面上从强制SSL切回时出现问题

[英]Problem switching back from forced SSL on certain pages using mod_rewrite

Client wants login pages to load via https. 客户希望通过https加载登录页面。 This is easily accomplished, but since the site uses pretty url's, we now stay in https mode when clicking around after login is finished. 这很容易实现,但是由于该站点使用了漂亮的url,因此现在登录完成后单击鼠标左键时,我们将保持https模式。 This breaks secure files which are uploaded in the CMS, stored above webroot, and downloaded by streaming through a php script if user has the appropriate permissions. 如果用户具有适当的权限,这将破坏安全文件,这些文件将上传到CMS中,存储在webroot上方,并通过php脚本通过流传输进行下载。 So, we need to switch back to regular http when we're no longer on a login page. 因此,当我们不再登录页面时,我们需要切换回常规http。 Here's what I have in my .htaccess file: 这是我的.htaccess文件中的内容:

RewriteEngine On
Options +FollowSymLinks

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^(login\.php|members\.php)$ https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(login\.php|members\.php)$ https://www.%{HTTP_HOST}%{REQUEST_URI}

RewriteCond %{HTTPS} on
RewriteCond %{IS_SUBREQ} false
RewriteRule !^(login\.php|members\.php)$ http://%{HTTP_HOST}%{REQUEST_URI}

Everything is working fine except the last line, which is getting confused by the pretty url's and redirecting to view.php (which handles translating pretty url lookup codes to database id's that are used in the querystring) if I use {REQUEST_URI}, and the homepage if I use $1 or the path. 如果我使用{REQUEST_URI},则最后一行除外,一切都工作正常,最后一行使漂亮的url困惑,并重定向到view.php(用于将漂亮的url查找代码转换为查询字符串中使用的数据库ID),并且主页(如果我使用$ 1或路径)。

I need to figure out a way to make this rewrite to switch back to http mode bypass the pretty url rewrite, but I don't know how to get the actual address that was typed in rather than what it was rewritten to by Apache. 我需要找出一种方法来使此重写绕过漂亮的url重写,从而切换回http模式,但是我不知道如何获取键入的实际地址,而不是如何获得Apache重写的地址。

Please help and thanks in advance! 请帮助并提前致谢!

You could grab the original requested URI path from the request line in THE_REQUEST : 您可以从THE_REQUEST请求行中获取原始请求的URI路径:

RewriteCond %{HTTPS} on
RewriteCond %{IS_SUBREQ} false
RewriteCond %{THE_REQUEST} ^[A-Z]+\ ([^ ]+)
RewriteRule !^(login|members)\.php$ http://%{HTTP_HOST}%1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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