php – 在CodeIgniter中使用.htaccess强制HTTPS
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 在CodeIgniter中使用.htaccess强制HTTPS,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2420字,纯文字阅读大概需要4分钟。
内容图文
![php – 在CodeIgniter中使用.htaccess强制HTTPS](/upload/InfoBanner/zyjiaocheng/743/e7c139a6abad4784b9385c7dd7051321.jpg)
我现有的.htaccess完全从我的URL中删除了index.php:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|(.*)\.swf|images|robots\.txt|css|docs|cache)
RewriteRule ^(.*)$index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /application/errors/404.php
</IfModule>
我需要整个站点运行SSL,而我的托管公司Pagoda Box有一个专有的.htaccess编辑器,可以从http切换到https:
RewriteCond %{HTTP:X-Forwarded-Proto} = http
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]
它仅在第一个条件语句的末尾添加时才有效,并且它完美地工作:它将https添加到裸URL并删除index.php.
但是,如果您从地址栏中的https中选择s并将其删除,则会返回index.php,并重复URL的最后一段.如果我输入完整的URL,从http://开始,它会重定向并完美地工作 – 只有当我将光标放在s前面并删除它才能使网站中断.
关于如何阻止这种新情况和规则与我现有文件冲突的任何想法?
解决方法:
对于任何CI / Pagoda Box用户,这里对我有用:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$https://%{HTTP_HOST}/$1 [R,L]
RewriteBase /
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|(.*)\.swf|images|robots\.txt|css|js|docs|cache)
RewriteRule ^(.*)$index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /application/errors/404.php
</IfModule>
请注意,RewriteBase位于https重定向之后,[L]结束处理.
内容总结
以上是互联网集市为您收集整理的php – 在CodeIgniter中使用.htaccess强制HTTPS全部内容,希望文章能够帮你解决php – 在CodeIgniter中使用.htaccess强制HTTPS所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。