我在将 url 中的电子邮件地址传递给 symfony 应用程序时遇到了一些问题.
I'm having some issues with passing an email address in a url to a symfony app.
网址看起来像
example.com/unsubscribe/email/me@example.com
它总是会导致 sfError404Exception
,除非删除了句点.在进行了一些谷歌搜索之后,我看到的唯一解决方案是 htaccess 由于存在时间段而绕过了 url.但是,当我将建议的修复添加到 htaccess 时,如下所示:
It will always result in a sfError404Exception
, except when the period is removed. After doing some googling around, the only solution I've yet seen is that htaccess is bypassing the url because of the period present. However, when I add the suggested fix to htaccess, like so:
# we skip all files with .something
RewriteCond %{REQUEST_URI} ..+$
RewriteCond %{REQUEST_URI} !@.+ #skip email address
RewriteCond %{REQUEST_URI} .epl$
RewriteCond %{REQUEST_URI} !.html$
RewriteCond %{REQUEST_URI} !.rhtml$
RewriteRule .* - [L]
我得到相同的 404.当我直接在 url (example.com/index.php/unsubscribe/email/me@example.com
) 中使用前端控制器时,它也会返回 404.我试过将转义版本直接放入地址栏,例如 example.com/unsubscribe/me%40example%2Ecom
并且这有效,但仅在 Firefox 中,没有其他地方.
I get the same 404. It also returns 404 when I use the front controller directly in the url (example.com/index.php/unsubscribe/email/me@example.com
). I've tried putting the escaped version directly into the address bar, eg example.com/unsubscribe/me%40example%2Ecom
and this works, but only in firefox, nowhere else.
此时我已经在论坛上用了大约 2 个小时的谷歌搜索来回答问题,但我的想法已经用完了.
I've spent about 2 hours in forum answer googling hell at this point and I'm running out of ideas.
有什么想法吗?
谢谢.
更新:这是routing.yml的相关部分:
Update: Here is the relevant section of the routing.yml:
unsubscribeform:
url: /unsubscribe/email/:email
param: { module: subscribe, action: index }
更新:堆栈跟踪......看起来它没有得到任何路由信息给我
Update: Stack trace ... looks like its not getting any route information to go on to me
404 | Not Found | sfError404Exception
Empty module and/or action after parsing the URL "/unsubscribe/email/me@example.com" (/).
stack trace
1. at ()
in SF_SYMFONY_LIB_DIR/controller/sfFrontWebController.class.php line 44 ...
41.
42. if (empty($moduleName) || empty($actionName))
43. {
44. throw new sfError404Exception(sprintf('Empty module and/or action after parsing the URL "%s" (%s/%s).', $request->getPathInfo(), $moduleName, $actionName));
45. }
46.
47. // make the first request
2. at sfFrontWebController->dispatch()
in SF_SYMFONY_LIB_DIR/util/sfContext.class.php line 159 ...
156. */
157. public function dispatch()
158. {
159. $this->getController()->dispatch();
160. }
161.
162. /**
3. at sfContext->dispatch()
in /home/web/htdocs/index.php line 10 ...
7. require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'ProjectConfiguration.class.php');
8.
9. $configuration = ProjectConfiguration::getApplicationConfiguration(SF_APP, SF_ENVIRONMENT, SF_DEBUG);
10. sfContext::createInstance($configuration)->dispatch();
11.
默认情况下,Symfony 将 .
和 /
视为参数分隔符.
这使得匹配这样的网址变得非常容易:
By default, Symfony treats .
and /
as parameter separators.
That makes it very easy to match a url like so:
/some/path/:param.:ext
但对电子邮件地址没有帮助.
But doesn't help with email addresses.
幸运的是,您可以通过指定自己的模式来覆盖 .
分隔符.
只需将下面的 requirements
行添加到您的路由中:
Fortunately, you can override the .
separator by specifying your own pattern.
Just add the requirements
line below to your routing:
unsubscribeform:
url: /unsubscribe/email/:email
param: { module: subscribe, action: index }
requirements: { email: .+ }
需求中的 .+
是一个匹配任何东西的正则表达式..
匹配任意字符,+
表示匹配一个或多个.
The .+
in the requirement is a regular expression matching anything. The .
matches any character, and the +
means match one-or-more.
(在 Symfony 1.4 中测试)
(Tested in Symfony 1.4)
这篇关于Symfony:电子邮件地址作为请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!