Tih*_*hom 3 redirect codeigniter get http-status-code-404
我在使用代码点火器路由时遇到困难.
http://www.mysite.com转到正确的控制器并做正确的事情.但是,http://www.mysite.com/?ref = p&t2 = 455会导致404错误.另外http://www.mysite.com/mycontroller/mymethod/?ref=p&t2=455也能正常工作.
我更改了config.php文件中的uri_protocol并尝试了不同的值.汽车似乎工作得最好.
我的理论是代码点火器正在使用查询参数来进行路由.问题是这些查询参数与路由无关.
如何告诉代码点火器忽略默认控制器的查询参数?
请注意,我按照说明在线删除了URL中的index.php.我不认为它导致了问题,但这是我的.htaccess文件以防万一:
RewriteEngine On
RewriteBase /~trifecta/prod/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'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
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
Run Code Online (Sandbox Code Playgroud)
使用该重写规则RewriteRule ^(.*)$ /index.php?/$1
,以下是一些正在发生的重写的示例:
http://www.mysite.com
=>
http://www.mysite.com/index.php?/
(实际上,这根本不会被重写)
http://www.mysite.com/mycontroller/mymethod/?ref=p&t2=455
=>
http://www.mysite.com/index.php?/mycontroller/mymethod/?ref=p&t2=455
http://www.mysite.com/?ref=p&ts=455
=>
http://www.mysite.com/index.php?/?ref=p&t2=455
无论是否正在重写,第一个都将起作用.CodeIgniter正在处理一个空查询字符串(很容易)或一个简单的"/"查询字符串.
第二个(也可以工作)正在被重写,但CodeIgniter能够处理它的查询字符串,即/mycontroller/mymethod/?ref=p&t2=455
.CI将其转换为一系列段
[0] => mycontroller
[1] => mymethod
[2] => ?ref=p&t2=455
Run Code Online (Sandbox Code Playgroud)
数组索引2最终会被你正在做的任何事情忽略.
第三个(它不起作用正在被重写,CodeIgniter根本无法处理它的查询字符串.它的查询字符串被重写为:/?ref=p&t2=455
.这使得一个段的数组看起来像这样:
[0] => ?ref=p&t2=455
Run Code Online (Sandbox Code Playgroud)
与您网站上的任何控制器都不匹配.
也许,您将通过修改RewriteRule
RewriteRule ^(.*)$ /index.php?/$1
来修复整个事情
RewriteRule ^(.*)$ /index.php/$1
,此时您可能希望将uri_protocol
配置更改回PATH_INFO
.