查询字符串作为 url 的一部分
我有一个带有查询字符串 http://www.sample.com?q=asdasdsdasd 的网址。是否可以修改查询字符串,以便我可以用 /myaccount 替换它,即最后的 url 看起来像 http ://www.sample.com/myaccount。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
查看 url重写。您可能无法直接访问 /myaccount,但您可以整理您的网址,使它们对 SEO 更具可读性和意义。
您将能够使用 使您的 url 看起来类似于以下内容:
如果您完全丢失了查询字符串,您将根本无法访问它。除非您实现了某种形式的临时代码来获取查询字符串,将其存储在会话中,然后重定向到您的
/myaccount
url 并将其返回。Check out url rewriting. You may not be able to achieve the /myaccount direct, but you can tidy up your urls, make them more readable and meaningful for SEO.
You will be able to use to allow your url to look similar to the following :
If you lose the query string all together you won't be able to access it at all. Unless you implemented some form of interim code that will get the query string, store it in a session and then redirect to your
/myaccount
url and get it back there.我认为你指的是 URL 重写。
这是一篇关于 URL 重写的常用博客文章:
"="">http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
或者如果您有 IIS7 ,现在变得更容易:
http://www.iis.net/download/urlrewrite
在的条款不过,将
?q=asdasdsdasd
更改为/myaccount
,我不明白。第一个 URL 看起来像一个典型的搜索查询,第二个 URL 可能会使用 cookie 等来获取变量(因为它用于用户帐户?)。但是可以使用 URL 重写,这样如果您的用户配置文件的 URL 如下所示:
www.sample.com?userprofile.aspx?user=johnsmith
这可以使用
johnsmith 进行重写
部分作为变量,例如:www.sample.com/user/johnsmith
I think you are referring to URL Rewriting.
This is quite a commonly used blog post regarding URL rewriting:
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
Or if you have IIS7, its now been made easier:
http://www.iis.net/download/urlrewrite
In terms of changing
?q=asdasdsdasd
to/myaccount
though, I don't understand. The first URL seems like a typical search query, and the second is a URL which would probably use cookies etc to pick up the variables (as its for a user account?).But URL Rewriting can be used so that if you have a user profile with a URL like:
www.sample.com?userprofile.aspx?user=johnsmith
This can be rewritten, using the
johnsmith
part as a variable like:www.sample.com/user/johnsmith
通过简单的字符串操作,您可以这样做:
With simple string manipulation you could do it as:
在 Global.asax 中使用此代码:
然后使用此地址
http://www.sample.com/myaccount/asdasdasd
Use the this Code in your Global.asax:
and then use this address
http://www.sample.com/myaccount/asdasdasd