Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

According to CI's docs, CodeIgniter uses a segment-based approach, for example:

example.com/my/group

If I want to find a specific group (id=5), I can visit

example.com/my/group/5

And in the controller, define

function group($id='') {
    ...
    }

Now I want to use the traditional approach, which CI calls "query string" URL. Example:

example.com/my/group?id=5

If I go to this URL directly, I get a 404 page not found. So how can I enable this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
369 views
Welcome To Ask or Share your Answers For Others

1 Answer

For reliable use of query strings I've found you need to do 3 things

  1. In application/config/config.php set $config['enable_query_strings'] = true;
  2. Again in application/config/config.php set $config['uri_protocol'] = "PATH_INFO";
  3. Change your .htaccess to remove the ? (if present) in the rewrite rule

I use the following

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...