duanla4959 2013-06-13 12:09
浏览 178
已采纳

从URL隐藏GET参数

How to hide URL GET parameters (http://domain.com/MyFirstYii/page?view=about). I've searched lot of posts. They all are saying about rewrite and URL manager, but i couldn't achieve what i want. :(

My scenario is,

I just want to hide the URL GET parameters.

Eg:

http://domain.com/MyFirstYii/page***?view=about***

I wanted to hide ***?view=about***.

Then URL should look like this http://domain.com/MyFirstYii/page. Other pages like this http://domain.com/MyFirstYii/post. In a simple words my GET parameters should act like POST parameters.

Thanks in Advance.

Edit:

I want to create some rules in the URLManager, but what kind of rules will hide the GET parameter.

  • 写回答

5条回答 默认 最新

  • douan6815 2013-06-13 13:58
    关注

    \w in regexp means „word“ character and such url part as „my-prety-page“ will NOT match. To hide GET params you must improve your urlManager rules. You can write such a rule for pages using SEF urls:

    '<controller:\w+>/<id:\d+>/<title:[^\/]*>/*' => '<controller>/view'
    

    In this case when you enter url

    http://example.com/page/12/my-prety-title
    

    a Page controller will be called to perform view action with id and title as arguments. It is the same if you enter this url:

    http://example.com/page/view?id=12&title=my-prety-title
    

    The last part /* in rule allows to keep additional params. E.g. if your address is

    http://example.com/user/55/john-doe-junior/foo/bar/
    

    in UserController's actionView you can write

    echo '<pre>' ;
    print_r($_GET);
    echo '</pre>' ;
    die();
    

    and you'll see

    Array
    (
        [id] => 55
        [title] => john-doe-junior
        [foo] => bar
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!