Hide GET parameter from URL

后端 未结 5 1455
故里飘歌
故里飘歌 2020-12-18 08:44

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\'

5条回答
  •  情深已故
    2020-12-18 09:25

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

    '///*' => '/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 '
    ' ;
    print_r($_GET);
    echo '
    ' ; die();

    and you'll see

    Array
    (
        [id] => 55
        [title] => john-doe-junior
        [foo] => bar
    )
    

提交回复
热议问题