Problems reassigning re-creation of code with GET parameters

I'm having difficulty routing my code.

http://www.mysite.com goes to the right controller and does everything right. However, http://www.mysite.com/?ref=p&t2=455 causes a 404 error. Also http://www.mysite.com/mycontroller/mymethod/?ref=p&t2=455 works fine.

I changed uri_protocol in config.php file and tried different values. It seems that the car works best.

My theory is that a code igniter uses query parameters to perform routing. The problem is that this query parameter has nothing to do with routing.

How can I say that a code igniter ignores request parameters for the controller by default?

Note. I followed the instructions online to remove index.php from the URL. I don't think this is causing the problem, but here is my .htaccess file just in case:

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]
+3
source share
5 answers

With this rewrite rule RewriteRule ^(.*)$ /index.php?/$1, here are some examples of rewrites that occur:

http://www.mysite.com=>
http://www.mysite.com/index.php?/(in fact, this cannot 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

The first will work whether it will be rewritten or not. CodeIgniter processes either an empty query string (which is easy) or a query string simply "/".

( ) , CodeIgniter , /mycontroller/mymethod/?ref=p&t2=455. CI

[0] => mycontroller
[1] => mymethod
[2] => ?ref=p&t2=455

2 , .

( , , CodeIgniter . : /?ref=p&t2=455. , :

[0] => ?ref=p&t2=455

.

, , RewriteRule RewriteRule ^(.*)$ /index.php?/$1 to
RewriteRule ^(.*)$ /index.php/$1
, , uri_protocol PATH_INFO.

+5

, , CodeIgniter , / .htaccess. - . mymethod index _remap() :

function _remap($method)
{
    if ($method == 'index' && count($_GET) > 0)
    {
        $this->mymethod();
    }
    else
    {
        $this->index();
    }
}
0

. http://www.site.com/?x=y .

.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]

//Config/config.php

$config['base_url'] = "http://www.site.com/";
$config['index_page'] = "";
$config['uri_protocol'] = "PATH_INFO";
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?';

? URL-. , . CodeIgniter, . , .

0

: 1. .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

, , , ...

  1. index.php , :

$pattern = "/\?.*$/"; $ replacement = ''; $ _SERVER ['REQUEST_URI'] = preg_replace ($ pattern, $replacement, $_SERVER ['REQUEST_URI']);

codeigniter . $_GET? $_SERVER ['REDIRECT_QUERY_STRING'], , mod_rewrite, .

0

CodeIgniter Super.htaccess

0

Source: https://habr.com/ru/post/1756106/


All Articles