开发者

redirect() Adds a question mark before the URI segment

I've recently enabled enable_query_strings in CodeIgniter'开发者_运维百科s config because when i tried to redirect to something like redirect('/blog?foo=bar') it removes the GET parameters but enable_query_strings fixed that..

The issue is that now when i do:

redirect('/blog');

it adds a ? to the url: http://www.domain.com/?/blog

How to fix that? or how to solve the primary issue without enabling query_strings?


I'd recommend just using header('location:/blog?foo=bar'); instead.


Read up on what enable_query_strings actually does and make sure this is actually what you want. It is not in fact a way to simply enable $_GET.

Confusing, I know. Please check out the latest version (2.0.2 currently) and enable the config option allow_get_array instead. This allows normal $_GET support to CI.

enable_query_strings was some weird psuedo-experimental feature that persists in new versions for some reason (do people really use it?). It is not, and never was, a way to use $_GET in the normal usage that we all know.

EDIT: Looks like all the url helpers, and all the functions that figure out your urls for you are busted if you enable this.

From the User Guide on enable_query_strings:

Please note: If you are using query strings you will have to build your own URLs, rather than utilizing the URL helpers (and other helpers that generate URLs, like some of the form helpers) as these are designed to work with segment based URLs.

So, if you're sure this is what you want, Karl's answer (using vanilla php's header to redirect) is pretty much your only hope. Or, you can try to provide a full URL, seeing as base_url() is probably broken now too (?):

redirect('http://full-urls-are-tedious.com/blog');

But this may not even work...


hope this will help you ! no need to change htaccess,just change your code.

redirect(base_url()."controller_name/function_name");


Why are you using query strings? CodeIgniters router will take care of this for you. You can create a router path that is shorter is you want but the basic structure is this:

http://www.somedomain.com/controller/function/param1/param2/...etc

So you could just go to this:

http://www.somedomain.com/blog/foo/bar

or

http://www.somedomain.com/blog/post/3

You can also use the router config to change it to something like this:

http://www.somedomain.com/blog/3

You really should use your CRUD functions that come with it.
http://codeigniter.com/user_guide/general/urls.html
http://codeigniter.com/user_guide/general/routing.html
http://codeigniter.com/user_guide/libraries/uri.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜