Cakephp 3.1-如何根据查询字符串值重定向? [英] Cakephp 3.1 - How to redirect based on query string values?

查看:92
本文介绍了Cakephp 3.1-如何根据查询字符串值重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近将网站从纯php更新到cakephp 3,并且在将具有参数的网址重定向到新网址时遇到了麻烦。

We recently updated our site from pure php to cakephp 3 and having trouble redirecting urls that have params to a new url.

例如,这种重定向工作正常

For example this redirect works fine

$routes->redirect('/webcast.php', '/webcast', ['status' => 302]);

但是,如果有参数,则不起作用

But if there's parameters, it doesn't work

$routes->redirect('/webcast.php?id=100', '/webcast', ['status' => 302]);

有什么想法吗?

谢谢。

推荐答案

路由器不支持匹配查询字符串,在检查匹配路由时传递给路由器的URL将不再附加任何查询字符串值。

The router doesn't support matching on query strings, the URL passed to the router when checking for a matching route won't have any query string values attached anymore.

尽管可以通过以下方法解决此问题使用自定义路由调度程序筛选器,自定义/扩展的 Router 类和自定义/扩展的 RouteCollection 类,这似乎

While it would be possible to workaround this by using a custom routing dispatcher filter, a custom/extended Router class, and a custom/extended RouteCollection class, this seems like way too much work for something that can easily be defined as for example a rewrite rule on server level.

Apache mod_rewrite c>示例:

Apache mod_rewrite example:

RewriteCond %{QUERY_STRING} ^id=100$
RewriteRule ^webcast\.php$ /webcast? [L,R=302]

并注意> 301 通常是首选的重定向方法

And note that 301 is usually the preferred redirect method.

另请参见

这篇关于Cakephp 3.1-如何根据查询字符串值重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆