I am trying to route a URL using codeigniter URL routing.
I want to redirect a url like
- /users/edit?email to userController/editemail
- /users/edit?password to userController/editpassword
I tried using the following line in routes.php in config folder
$route["users/edit?(email|password)"] = "userController/edit$1";
This displays page not found. I am guessing that ? is being treated as a regular expression character. I tried escaping it but that didn’t work either.
I don’t want to set the config setting uri_protocol to PATH_INFO or QUERY_STRING, since this is just a pretty URL I want to setup, not pass anything to the action.
Can somebody help me out over here?
Regards
You should escape the
?like this, it should work. (not tested)Later edit:
This works as intended:
The
userControllerlooks like thisRouter works like this:
http://sitename/index.php/users/editemailyou seeeditemail()action.http://sitename/index.php/users/editpasswordyou seeeditpassword()action.http://sitename/index.php/users/edityou see theedit()action (the question mark makes optional the email/password field and you can do some other things inedit()action