具有无扩展 URL 路由的相对 URL
我对 URL 路由不熟悉,但我正在计划它的工作方式,以便我可以将 products.aspx?category=cars
这样的 URL 显示为 products/cars
。
我看到的最大问题是,如果在带有重新路由 URL 的页面上有指向 products.aspx?category=food
的链接,浏览器不会将用户发送到 products/cars/ products.aspx?category=food
?
我错了还是有办法解决这个问题?
I new to URL routing, but I'm planning out how it will work so I can have a URL like products.aspx?category=cars
appear as products/cars
.
Biggest problem I can see happening is that if have a link to products.aspx?category=food
on a page with a rerouted URL wouldn't the browser send the user to products/cars/products.aspx?category=food
?
Am I wrong or is there a way to get around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它将发送到 products/cars/products.aspx?category=food,正确。
您可以通过在网址中添加前面的“/”来解决此问题,使其变为 /products.aspx?category=food
但是,如果您进行网址映射,您不想将链接构建为“产品/食品”,以便它们可以重写吗?
It will send it to products/cars/products.aspx?category=food, correct.
You can solve this by adding a preceeding '/' to your url so it becomes /products.aspx?category=food
However if you're URL mapping won't you want to build your links as "products/food" so that they can be rewritten?
您所追求的是 URL 重写或友好 URL。这是一个可能对 ASP.NET 有帮助的链接我自己不使用 NET,所以不确定
http://www.codeproject.com/Articles/18318/URL-Mapping-URL-Rewriting-Search-Engine-Friendly-U
但这可能有帮助:
http://en.wikipedia.org/wiki/Rewrite_engine
What you are after is URL Rewriting or Friendly URLS. Heres a link that might help for ASP.NET I do not use NET myself so not sure
http://www.codeproject.com/Articles/18318/URL-Mapping-URL-Rewriting-Search-Engine-Friendly-U
But this might help:
http://en.wikipedia.org/wiki/Rewrite_engine
通常,通过 URL 重写,您将始终使用 index.aspx。您的所有路径都将按照您建立的模式进行设置。
index.aspx?display=products&category=food
将变成
mysite.com/products/food
或者
mysite.com/products/category/food
您可以使用特定的重写工具通过配置选项自定义处理此问题的方式。
Typically, with URL rewriting, you are always going to be using index.aspx. All of your paths will be setup with a pattern you establish.
index.aspx?display=products&category=food
would turn into
mysite.com/products/food
or
mysite.com/products/category/food
You are able to customize how you handle this with configuration options with your particular rewriting tool.