Cakephp 3.1 - How to redirect based on query string values?

前端 未结 1 1854
梦毁少年i
梦毁少年i 2021-01-26 17:24

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



        
相关标签:
1条回答
  • 2021-01-26 18:01

    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.

    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 example:

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

    And note that 301 is usually the preferred redirect method.

    See also

    • Apache > HTTP Server > Documentation > Version 2.4 > Apache mod_rewrite
    0 讨论(0)
提交回复
热议问题