How to preserve plus signs (+) in URL?

There’s a route in my application that contains a user’s email address, which can contain a plus sign. An example url is /manage/ However when the URL is parsed and decoded, the plus sign gets converted to a space so I’m unable to locate the correct user based on email in the action.

I’ve found that I can fix the problem by overriding CHttpRequest’s decodePathInfo function to call


instead of


on line 264. I’d rather not modify this function though, since it’s called on every page load, and after changing it to use rawurldecode, uploading images with spaces in the file name no longer works.

Has anyone else experienced this or knows of a way to fix it? Thanks in advance.

How you create this url?

$url = '/manage/'.urlencode($email);

I’ve tried using rawurlencode here instead of urlencode, but that doesn’t solve the problem.

Try createUrl() method:

$url = Yii::app()->createUrl('controller/action', array('email' => $email));

Thanks for the help–using createUrl lead me to the problem. Apache was redirecting URLs without trailing slashes to one with a trailing slash, so


was redirected to


Somewhere in the redirection process, the %2B was converted to a plus sign, which was then converted to a space when Yii decoded the URL. Ensuring the the URL starts with a trailing slash fixed the issue.