Reputation: 10071
I am trying to route a URL using codeigniter URL routing. I want to redirect a url like
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
Upvotes: 0
Views: 934
Reputation: 5356
You should escape the ?
like this, it should work. (not tested)
$route["users/edit\?(email|password)"] = "userController/edit$1";
Later edit:
This works as intended:
$route["users/edit(email|password)?"] = "userController/edit$1";
The userController
looks like this
<?php
class UserController extends Controller {
function edit()
{
echo "general edit";
}
function editemail()
{
echo "edit email!";
}
function editpassword()
{
echo "edit password";
}
}
Router works like this:
http://sitename/index.php/users/editemail
you see editemail()
action.http://sitename/index.php/users/editpassword
you see editpassword()
action.http://sitename/index.php/users/edit
you see the edit()
action (the question mark makes optional the email/password field and you can do some other things in edit()
actionUpvotes: 0