在 SimpleHTTPServer.py 中重定向浏览器? [英] redirect browser in SimpleHTTPServer.py?

查看:33
本文介绍了在 SimpleHTTPServer.py 中重定向浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我部分是通过实现 SimpleHTTPServer.py 在方案中.我对 HTTP 请求/响应机制很感兴趣.在浏览上述文件时,我遇到了这个 - #redirect browser - 在代码中基本上做 apache 所做的事情".

I am partially through implementing the functionality of SimpleHTTPServer.py in Scheme. I am having some good fun with HTTP request/response mechanism. While going through the above file, I came across this- " # redirect browser - doing basically what apache does" in the code".

为什么在这种情况下需要这种重定向?

Why is this redirection necessary in such a scenario?

推荐答案

想象你服务一个页面

http://mydomain.com/bla

包含

<a href="more.html">Read more...</a>

点击时,用户的浏览器将检索http://mydomain.com/more.html.如果你改为服务

On click, the user's browser would retrieve http://mydomain.com/more.html. Had you instead served

http://mydomain.com/bla/

(具有相同的内容),浏览器将检索 http://mydomain.com/bla/more.html.为避免这种歧义,重定向会在 URL 指向目录时附加一个斜杠.

(with the same content), the browser would retrieve http://mydomain.com/bla/more.html. To avoid this ambiguity, the redirection appends a slash if the URL points to a directory.

这篇关于在 SimpleHTTPServer.py 中重定向浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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