How to handle dot in Symfony URL
This problem with dot in Symfony URL is a common issue faced by developers. I’ve seen people asking about it few times in the symfony-users mailing list, and in fact I have asked about it once. Here’s one recent thread about it in the mailing list.
Symptom
When you have dot in your Symfony URL, e.g.: “http://localhost/mysymfonyapp/module1/action1/param1/do.do.do”, your web application suddenly behaves incorrectly. Either error or something. After debugging, you’d find that the erratic behavior is caused by parameter ‘param1′ not containing ‘do.do.do’ (as it should do … does?).
Cause
I found that the problem is caused by Symfony’s web/.htaccess. Especially the following line (red):
# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* – [L]
The above htaccess rule basically (as the comment says) skip all URL with dot in it, because it suppose to be URL to image, css, or javascript files. But sometime we do have dot in URL other than for accessing those files, for example if we pass email address in the URL.
Solution
There are two possible solutions that I know of.
One solution is to use question mark formatted parameter (e.g.: “module/action?email=bla@blu.com” as opposed to “module/action/email/bla@blu.com”) as pointed out here. I have not tried this myself but seems like a good solution.
The next possible solution is to modify web/.htaccess to suit your situation. For example, in my situation, I needed the dot because it was for email address. So I added the following line (green) which basically tells apache not to skip the URL even if it has dot if it has @ sign:
# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !@.+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* – [L]
I hope that helps…
Update:
- Thanks to Nicolas Perriault from Symfony users mailing list (he developed symfonians.net). He uses this .htaccess (http://pastie.org/330755) for symfonians.net. I did a quick test and seems to work nicely.
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
Thanks!
This post was very helpful to solve my problem.
Greetings from Germany
@Martin
Thanks for leaving a comment :)