我应该如何结构,MVC htaccess的应用我的查询字符串? [英] How should I structure my query string in MVC htaccess applications?

查看:92
本文介绍了我应该如何结构,MVC htaccess的应用我的查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何创建一个Web应用程序假的网址查询。当你把一个的.htaccess 文件中的一个项目的根文件夹,你可以重写(幕后)这个网址 http://www.website .COM /博客/视图 http://www.website.com/index.php?q=blog/view 。这样,你可以保持一个接入点和 $创建一个MVC应用程序出了路径_ GET [Q]

I was wondering about creating "fake" URL queries in a web application. When you put a .htaccess file in the root folder of a project you can rewrite (behind the scenes) this URL http://www.website.com/blog/view into http://www.website.com/index.php?q=blog/view. That way you can maintain a single access point and create a MVC application out of the path in $_GET["q"].

但对于实际的查询字符串?确实地这种类型的改写不提供输入变量的查询字符串的灵活性。因此,我很喜欢下面的想法:

But what about actual query strings? Surely this type of rewrite doesn't offer the flexibility of inputting a variable query string. Thus I liked the idea of the following:

http://www.website.com/blog/search?keywords=some+blog+post&limit=10&order=DESC

不过分钟你把&功放;在您的网址符号,事情就变得臭。出于这个原因,我目前正在更换和放大器;用符号|符号

But the minute you put & symbols in your URL, things get smelly. For that reason I'm currently replacing the & symbols with | symbols

http://www.website.com/blog/search?keywords=some+blog+post|limit=10|order=DESC

但现在用户可以通过错误地将打破我的应用程序A和符号在URL中。

But now a user could break my application by mistakenly putting a & symbol in the URL.

要总结,我想知道的是,如果有一种方法来转义&放大器;幕后的符号,这样我可以把和放大器;在URL中的符号,但我的应用程序会看到|符号(或类似的东西)

To sum up, what I'm wondering is if there is a way to "escape" the & symbols behind the scenes so that I could put & symbols in the URL, but my application would see | symbols (Or something like it)

使这一可能的任何其他方法,我也很乐意听到

Any other method of making this possible I would also love to hear

推荐答案

您要使用的查询字符串附加( [QSA] )标志在你的重写规则的结束在你的.htaccess文件。

You want to use the Query String Append ([QSA]) flag on the end of your RewriteRule in your .htaccess file.

例如:

RewriteRule ^(.*)$ index.php?request=$1 [L,QSA] 

在规则中的[QSA]标志说采取任何pre-现有的GET参数,并将它们连接到新的URI。所以这样的:

The [QSA] flag on the rule says to take any pre-existing GET parameters and attach them to the new URI. So this:

http://www.example.com/blog?post=123

成为本:

http://www.example.com/index.php?request=blog&post=123

这篇关于我应该如何结构,MVC htaccess的应用我的查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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