Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mod rewrite htaccess(https到http)_Mod Rewrite_Codeigniter_Redirect_Https_Url Scheme - Fatal编程技术网

Mod rewrite htaccess(https到http)

Mod rewrite htaccess(https到http),mod-rewrite,codeigniter,redirect,https,url-scheme,Mod Rewrite,Codeigniter,Redirect,Https,Url Scheme,这是另一个问题。我已经做了我的文献回顾。非常感谢您的帮助 要求: 仅对少数URL强制使用HTTPS 浏览器不应该说SSL页面的部分加密页面 我正在使用CodeIgnitor,并将config.php中的base_url调整为: 所以,如果URL是通过https://访问的,则其中包含的所有链接也将位于https上,这是为了避免“部分加密页面”问题 我从以下htaccess代码开始: RewriteCond %{HTTPS} !on RewriteRule ^(.*)/(abc|xyz|pqr)(

这是另一个问题。我已经做了我的文献回顾。非常感谢您的帮助

要求:

  • 仅对少数URL强制使用HTTPS
  • 浏览器不应该说SSL页面的部分加密页面
  • 我正在使用CodeIgnitor,并将config.php中的base_url调整为:

    所以,如果URL是通过https://访问的,则其中包含的所有链接也将位于https上,这是为了避免“部分加密页面”问题

    我从以下htaccess代码开始:

    RewriteCond %{HTTPS} !on
    RewriteRule ^(.*)/(abc|xyz|pqr)(.*)$ https://%{HTTP_HOST}/cart/$2$3 [R=301,NC,L]
    
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !^(.*)/(abc|xyz|pqr)(.*)$ [NC]
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]
    
    使用此选项,任何具有abc、xyz或pqr的URL都将重定向到HTTPS,任何不具有它的URL都将强制返回HTTP

    这工作得很好,唯一的问题是它无法避免“部分加密页面”问题。例如,如果我选择url,它将被重定向到。但是这个页面上的链接说,由于后一个重写规则,将更改为HTTP。从而使页面部分加密

    我也尝试过像这样添加http_referer check来解决这个问题,但显然这无法解决这个问题。因为任何来自HTTPS页面的点击都不会转换为HTTP

    RewriteCond %{HTTPS} !on
    RewriteRule ^(.*)/(abc|xyz|pqr)(.*)$ https://%{HTTP_HOST}/cart/$2$3 [R=301,NC,L]
    
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_REFERER} !^(https)(.*)$
    RewriteCond %{REQUEST_URI} !^(.*)/(abc|xyz|pqr)(.*)$ [NC]
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]
    
    我只是想知道是否有更好的方法来解决这个简单的问题,还是我做得不对。使用CI钩子而不是.htaccess会解决这个问题吗


    提前感谢

    您可以将您的静态内容放在不同的域(如static.example.com)上,并为此类请求禁用HTTPS到HTTP重定向

    使用
    //static.example.com/..
    引用该资源,以使用与引用所包含的文档相同的URI方案,并在您的
    重写规则中进行测试(如果请求此类资源):

    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} !=static.example.com
    RewriteRule !(^|/)(abc|xyz|pqr) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]
    

    好的。我想我找到了解决办法。我也在我的服务器上测试了它。很好。。 重写时也需要http引用条件

    RewriteCond %{HTTPS} !on
    RewriteRule ^(.*)/(abc|xyz|pqr)(.*)$ https://%{HTTP_HOST}/cart/$2$3 [R=301,NC,L]
    
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_REFERER} !^https(.*)/(abc|xyz|pqr)(.*)$ [NC]
    RewriteCond %{REQUEST_URI} !^(.*)/(abc|xyz|pqr)(.*)$ [NC]
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]
    
    现在,如果您访问任何带有(abc、xyz、pqr)的页面,它将被重定向到https://... 此外,所有嵌入的链接都将通过https提供服务。因此浏览器不会显示部分加密警告(状态栏上的红色警告标志)

    当您离开其中任何一个页面时,由于referer检查,该页面将位于ssl上,并且该页面可能显示部分加密的警告(但我可以接受)。一旦离开此页面,所有内容都将是非ssl的


    希望这对别人有帮助

    在这种情况下,如果example.com中的页面包含static.example.com中的内容,浏览器将显示部分加密的内容page@shikhar当前位置我澄清了我的陈述。我只是问。。你为什么不让用户的信息保密?
    RewriteCond %{HTTPS} !on
    RewriteRule ^(.*)/(abc|xyz|pqr)(.*)$ https://%{HTTP_HOST}/cart/$2$3 [R=301,NC,L]
    
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_REFERER} !^https(.*)/(abc|xyz|pqr)(.*)$ [NC]
    RewriteCond %{REQUEST_URI} !^(.*)/(abc|xyz|pqr)(.*)$ [NC]
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]