【发布时间】:2012-08-22 09:40:24
【问题描述】:
我现有的.htaccess 完美地从我的网址中删除了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 前面并删除它时,站点才会中断。
关于如何阻止这个新条件和规则与我现有文件冲突的任何想法?
【问题讨论】:
-
"只有当我将光标放在 "s" 前面并删除它时,站点才会中断"
-
致投反对票的人 - 我理解让社区保持一致,但如果您不在 cmets 中说您这样做并给出解释以帮助我纠正,那将是极不具建设性的我未来的罪行。
-
我不知道他们(托管公司)为什么不使用合理的东西,比如
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}。 -
@netcoder - 是的,他们有。隐藏 index.php,它涉及与 .htaccess 编辑协同工作的 codeigniter 路由和配置编辑,这与我的 https 重定向相冲突。如果其他人有这个问题,它可能会出现在 codeigniter 上,并且该标签有助于使其可找到。我刚刚在这个问题上浪费了 10 个小时的工作日。我正在重新添加标签。
-
@ShaquinTrifonoff 他们的解释在help.pagodabox.com/customer/portal/articles/175458-adding-ssl。是的,对于警察来说,这个评论是相关的,因为链接是 pagoda 的解释和 htaccess 编辑推荐。
标签: php .htaccess codeigniter