从URL隐藏GET参数 [英] Hide GET parameter from URL

查看:512
本文介绍了从URL隐藏GET参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何隐藏URL GET参数( http://domain.com/MyFirstYii/page?view = about ).我搜索了很多帖子.他们都在谈论重写和URL管理器,但是我无法实现我想要的. :(

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. :(

我的情况是

我只想隐藏URL GET参数.

I just want to hide the URL GET parameters.

例如:

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

我想隐藏***?view=about***.

然后URL应该看起来像这样http://domain.com/MyFirstYii/page.其他页面,例如http://domain.com/MyFirstYii/post.简而言之,我的GET参数应该像POST参数一样.

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.

在此先感谢.

我想在 URLManager 中创建一些规则,但是什么样的规则将隐藏GET参数.

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

推荐答案

\ w 意味着单词"字符和诸如"my-prety-page"之类的网址部分将不匹配. 要隐藏GET参数,您必须改进urlManager规则.您可以使用SEF网址为网页编写这样的规则:

\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

将调用页面控制器以id和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/

UserControlleractionView中,您可以编写

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

您会看到

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

这篇关于从URL隐藏GET参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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