如何在 yii 中将所有 url 转发到单个 url [英] How to forward all url to a single url in yii

查看:18
本文介绍了如何在 yii 中将所有 url 转发到单个 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何将所有 url 转发到 yii 中的单个 url所有链接都转到一个网址需要这个来显示维护消息

i need to know How to forward all url to a single url in yii all link go to a single url need this for showing maintenance message

推荐答案

更新

旧代码示例从 Yii 1.1.16 开始停止工作.感谢 JamesG(参见 评论)新的解决方案.代码示例已更新.

The old code sample stopped working since Yii 1.1.16. Thanks to JamesG (see comment) for the new solution. Code sample has been updated.

正如您已经发现的那样,catchAllRequest 是在 yii 中执行此操作的最佳方法.它是专门针对这种情况制作的,从 文档.使用它也可能会给你带来轻微的性能提升(超过 urlManager),但我怀疑它会很明显.

As you have already figured out, catchAllRequest is the best way to do this from within yii. It has been made specifically for such cases, as is quite evident from the documentation. Using it could also probably give you a slight performance increase (over urlManager), but i doubt that it'll be noticeable.

另一方面,如果您希望使用 urlManager,您可以尝试使用(也可以阅读代码示例中的注释):

On the other hand if you wish to use urlManager, you can try with (also read comments in code sample):

  1. 1.1.16 及以上版本:

  1. Version 1.1.16 and above:

'<url:(.*)>'=>'maintenance/index'

  • 1.1.15 及以下版本:

  • Version 1.1.15 and below:

    '<url:(.*)>'=>'maintenance/index'
    
    // '(.*)'=>'maintenance/index' // this used to work in previous versions ...
    // of Yii (below 1.1.16) mainly due to a bug, see notes
    

  • 注意:这必须是 urlManager 的 rules 数组配置中的第一条规则.

    Note: This will have to be the first rule in your urlManager's rules array configuration.

    然而,正如 sl4mmer 已经提到的,htaccess 或服务器配置是最好的方法,因为服务器在将请求发送到 php 之前首先捕获请求.

    However as already mentioned by sl4mmer, htaccess or server configuration is the best way to do this, since the server after all catches the request first before sending it to php.

    错误注意事项:检查 github 问题 这里.

    Note for Bug: Check github issue here.

    这篇关于如何在 yii 中将所有 url 转发到单个 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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