URL重写如何以纯英语工作 [英] how does URL rewrite work in plain english

查看:38
本文介绍了URL重写如何以纯英语工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多关于 URL 重写的内容,但我仍然不明白.

我知道像

这样的 URL

http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=19

可以换成更友好的,比如

http://www.example.com/Blog/2006/12/19/

并且服务器代码可以保持不变,因为有一些过滤器可以转换新 URL 并将其发送到旧 URL,但它是否也替换了响应的 HTML 中的 URL?

如果服务器代码保持不变,那么在我返回的 HTML 代码中可能有如下链接:

http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=20http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=21http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=22

如果在我的页面中我仍然有旧的 URL,这违背了拥有漂亮 URL 的目的.

URL 重写(使用过滤器或其他东西)是否也会替换 HTML 中的这些内容?

换句话说...重写规则是否适用于传入的请求以及响应的 HTML 内容?

谢谢!

解决方案

URL 重写器简单地获取传入的 URL,如果它匹配某个模式,它会将其转换为服务器理解的 URL(假设您的重写规则是正确的).

这确实意味着可以通过多种方式访问​​特定资源,但这并不能打败重点",因为重点是拥有漂亮的网址,而您仍然会这样做.>

他们不会重写传出的内容,只会重写传入的 URL.

I have read a lot about URL rewriting but I still don't get it.

I understand that a URL like

http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=19

can be replaced with a friendlier one like

http://www.example.com/Blog/2006/12/19/

and the server code can remain unchanged because there is some filter which transforms the new URL and sends it to the old, but does it replace the URLs in the HTML of the response too?

If the server code remains unchanged then it is possible that in my returned HTML code I have links like:

http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=20
http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=21
http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=22

This defeats the purpose of having the nice URLs if in my page I still have the old ones.

Does URL rewriting (with a filter or something) also replace this content in the HTML?

Put another way... do the rewrite rules apply for the incoming request as well as the HTML content of the response?

Thank you!

解决方案

The URL rewriter simply takes the incoming URL and if it matches a certain pattern it converts it to a URL that the server understands (assuming your rewrite rules are correct).

It does mean that a specific resource can be accessed multiple ways, but this does not "defeat the point", as the point is to have nice looking URLs, which you still do.

They do not rewrite the outgoing content, only the incoming URL.

这篇关于URL重写如何以纯英语工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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