URL rewriting problem CodeIgniter

Question:
 
I have problems with routing code igniter.
http://www.mysite.com goes to the controller of the right and doing the right thing. However, http://www.mysite.com/?ref=p&t2=455 causes an error 404. Http :/ / www.mysite.com/mycontroller/mymethod/?ref=p&t2=455 works well.
I changed the uri_protocol in config.php and tried different values. Auto seems to work best.
My theory is that code igniter using query parameters to the routing. The problem is that the query parameters have nothing to do with routing.
How can I tell code igniter to ignore query parameters to the default controller?
Note that I followed the online instructions to remove the index.php in the URL. I do not think that's causing a problem, but here is my htaccess file just in case.:
RewriteEngine  On 
RewriteBase  / ~ trifecta / prod /

# Removes access to the system folder by users. 
Additionally # Will this allow you to create a System.php controller, 
# Previously this Would not Have Been possible. 
# 'system' can be mittal if You have renamed your system folder. 
RewriteCond  % { REQUEST_URI }  ^ system . * 
RewriteRule  ^ (. *) $ / index . php ? / [L]
# Checks to see if the user is Attempting to access a valid file,
#: Such as an image or css document If This Is not true it sends the
# Request to index.php
RewriteCond% {REQUEST_FILENAME}!-F
RewriteCond% {REQUEST_FILENAME}!-D
# This last requirement Enables access to the pictures and css folders, and the robots.txt file
# Submitted by Michael Radlmaier (mradlmaier)
RewriteCond ^! (Index \ php |. Images | robots \ txt |. Css)
RewriteRule ^ (. *) $ Index.php? /  [ L ]
Answers 1

With this rewrite rule (. *)? RewriteRule ^ $ / index.php / $ 1 , some examples of rewriting that occur:
http://www.mysite.com => http://www.mysite.com/index.php?/ (in fact, it could not be rewritten at all)
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
First work if it is to be rewritten or not. CodeIgniter treats an empty query string (which is easy) or a query string to just "/".
The other (which also works) is to be rewritten, but CodeIgniter is capable of processing the query string, which is / MyController / MyMethod /? ref = t2 & p = 455 . IC that converts into a table segments as
[ 0 ]  => MyController
 [ 1 ]  => MyMethod
 [ 2 ]  =>  ? ref = p & t2 = 455
Index Table 2 finally gets ignored by all that you do.
The third argument (which work not done . was rewritten and CodeIgniter can not process the query string to all the query string is rewritten: ? / ref = p & t2 = 455 . This makes for an array of segments that resembles this:
[ 0 ]  =>  ? ref = p & t2 = 455
which does not correspond to any controller on your site.
Probably, you will fix all this by changing the RewriteRule RewriteRule ^ (. *) $ / index.php? / $ 1 To RewriteRule ^ (. *) $ / index.php / $ 1 at which point you'd probably want to change the uri_protocol config Return to PATH_INFO .


answer # 2

There seems to be a limitation of how CodeIgniter is designed, not as a result of your routing and / or . htaccess . Someone filed a bug report here . However, instead of using it and adding your MyMethod code in your index method of your controller by default, you can use the _remap () function as follows:
function _remap($method)
{
    if ($method == 'index' && count($_GET) > 0)
    {
        $this->mymethod();
    }
    else
    {
        $this->index();
    }
}
Answers 3

With the following configuration, it works fine for me. http://www.site.com/?x=y is routed to the index method of the default controller.
. Htaccess
RewriteEngine on
 RewriteCond   ! ^ ( index \. php ) 
RewriteRule  ^ (. *) $ index . php /  [ L ]
System / application / config / config.php
        ~ 0-9%: _ \ - '.? ;
Do not forget to add? to the list of characters in the URL. Perhaps this is a problem. I just tried this configuration with a new installation of CodeIgniter and it worked fine. These are the only changes I had to do.
Answers 4

Here is how I got around it: 1. I have a standard rewrite in htaccess.:
RewriteCond  % { REQUEST_FILENAME }  - f
 RewriteCond  % { REQUEST_FILENAME }  - d
 RewriteRule  (. *) ^ $ index . php ? /  [ QSA , L ]
This is probably independent but ...
  1. in the index.php file outside the application folder I added:
$ Pattern = "/ \ * $ /?." $ Replacement ='', $ _SERVER ['REQUEST_URI'] = preg_replace ($ pattern, $ replacement, _SERVER ['REQUEST_URI']) $;
This prevents codeigniter trying to use the query string in the query. Now you really need $ _GET? They must be analyzed off $ _SERVER ['REDIRECT_QUERY_STRING'] to be set if you use mod_rewrite as above.

Post a Comment

0 Comments