【问题标题】:Codeigniter remove index.php when redirected from non-www to wwwCodeigniter 从非 www 重定向到 www 时删除 index.php
【发布时间】:2018-03-31 09:19:23
【问题描述】:

我在基于 codeigniter 的网络应用中添加了从非 www 到 www 的强制重定向。

这样做后它工作正常,但它在 URL 中显示了一个额外的 index.php,我需要删除它。

这是我的网址:http://www.testprofile.com(工作正常)

这是导致问题的原因:

https://testprofile.com/result/184/1103511096450940jawadamin(非www网站,会自动加www)

打开上述 URL 会重定向到 www,但还会在 URL 中添加一个额外的 index.php,应该将其删除。

这是我的 .HTACCESS 的代码

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{HTTP_HOST} ^testprofile.com [NC]
RewriteRule ^(.*)$ https://www.testprofile.com/$1 [L,R=301]
</IfModule>

请帮我删除这个烦人的 index.php

谢谢,

【问题讨论】:

  • @wolfgang1983 我已经试过了,没有运气
  • 尝试切换规则位置:在RewriteEngine On 行之后剪切和粘贴最后两行。但你也需要在条件行中像^testprofile\.com 一样转义点。
  • @Tpojka,在条件行中添加 ^testprofile\.com 有效。谢谢

标签: .htaccess codeigniter https


【解决方案1】:

您错过了重写条件行右侧的转义点。应该是这样的

RewriteCond %{HTTP_HOST} ^testprofile\.com [NC]

或者在你的整个例子中

<IfModule mod_rewrite.c>
RewriteEngine On
#If in root of web server you can use next line or set it appropriate according to location on server
#RewriteBase /

RewriteCond %{HTTP_HOST} ^testprofile\.com [NC]
RewriteRule ^(.*)$ https://www.testprofile.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

如果反斜杠字符未保留点,则 apache 将其读取为通配符。您可以在this page 上找到一些有用的提示。

另外,您可以查看useful .htaccess snippets here

【讨论】:

  • 几天前我已经尝试过了,它按预期工作。再次感谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-12
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
相关资源
最近更新 更多