Parenthesis issue in codeigniter url

[亡魂溺海] 提交于 2019-12-12 00:24:31

问题


Few of my project urls contains the parenthesis and it is a codeigniter project. Unfortunately I cant remove them. So I am writing following rules in my route.php of config folder:

$route['abc-(def)'] = 'locations/index/12492';
$route['abc-%28def%29'] = 'locations/index/12492';
$route['404_override'] = 'home/pagenotfoundhandler';

So when I am trying to access URL http://mydomain.com/abc-(def) or http://mydomain.com/abc-%28def%29 it takes me to home/pagenotfoundhandler, while it should take me to location controller and index method. Please suggest how to deal with parenthesis in codeigniter.


回答1:


Well I guess that is because the page http://mydomain.com/abc-(def) which is supposed to redirect to locations/index/12492 can not be found! so a 404 - Page not Found error takes place, which of course as you have defined takes you to home/pagenotfoundhandler! make sure the path exists or even why do not you give the complete path to see if it works!




回答2:


The parentheses are a part of the regex pattern, so try escaping them if you want to use them as ascii characters like this:

$route['abc-\(def\)'] = 'locations/index/12492';

And one more place to look:

There should be a allowed uri characters setting in config.php for your codeigniter system. check there if parentheses are allowed.

Alternatively, you can disable $config["csrf_protection"] to skip url xss cleaning.



来源:https://stackoverflow.com/questions/17445869/parenthesis-issue-in-codeigniter-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!