gpt4 book ai didi

php - 在 CodeIgniter 中使用 .htaccess 强制使用 HTTPS

转载 作者:可可西里 更新时间:2023-11-01 00:23:25 26 4
gpt4 key购买 nike

我现有的 .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 的部分重复。如果我键入以 http:// 开头的完整 url,它会重定向并完美运行 - 只有当我将光标放在 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,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12149807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com