Blue Horn

Symfony Framework

How to handle dot in Symfony URL

December 4, 2008 by Sid in Symfony Framework with 2 Comments

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:

Tagged ,

Related Posts

2 Comments

  1. MartinDecember 15, 2009 at 12:47 am

    Thanks!
    This post was very helpful to solve my problem.

    Greetings from Germany

  2. SidJanuary 19, 2010 at 12:05 amAuthor

    @Martin

    Thanks for leaving a comment :)

Leave a reply

Your email address will not be published. Required fields are marked *

*

twenty + six =

My Projects
Restaurant Websites
Websites