URL重定向中内部重定向和外部重定向的区别

本文详细解释了内部重定向与外部重定向的区别。内部重定向指服务器内部改变请求路径,客户端地址栏显示不变;而外部重定向则由服务器通知客户端重新发送请求到新的URL,客户端地址栏显示更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

简单而言就是:

  内部重定向(重写)发生在server内部,client不知情,即浏览器上显示的是访问a.html但实际上收到的却是b.php;

  外部重定向则是server端通知client端需要更改URL,并舍弃之前的request。client按要求发送第二个request,server发送对应的文件。如,client第一次发送request要求访问a.html,server告知其这个url已经更改成b.php了,于是client发送request要求访问b.php,server发送b.php给client,并且此时用户看见浏览器URL栏里显示的是.../b.php


http://www.webmasterworld.com/apache/3524863.htm

With an external redirect, your server issues a response telling the requesting client, "That resource has moved - Ask for that content again using this new URL." At this point, the current HTTP request is terminated. The client (e.g. browser or robot) then starts a new HTTP transaction, re-requesting the desired resource using the new URL provided by the server. Because it is a new HTTP request, a browser will update its address bar to show the new URL.

External Redirect: 
Client: Issue HTTP request: "GET /page.html" 
Server: Send HTTP response: "/page.html has moved, ask for /page2.html instead." Close HTTP request. 
Client: Issue HTTP request: "/GET /page2.html" (Note that it is the client's option to follow the redirect.) 
Server: Send content of /page2.html, close HTTP request.

In contrast, an internal rewrite simply changes the server filepath associated with a requested URL. If no internal rewriting is applied, then by default, the server uses the part of the requested URL following the domain name as the filepath. But Apache mod_rewrite or ISAPI Rewrite on IIS can be used to completely change the filepath associated with a URL; The most visible example of this is the 'pointing' of all client URL requests to a single page-generation script on a server. Internal rewrites take place within the context of the client's original HTTP request, and the client is unaware that the server filepath used to retrieve or generate the requested content differs from the path-part of the URL it requested.

Internal Rewrite: 
Client: Issue HTTP request: "GET /page.html" 
Server: Internally rewrite client-requested URL "/page.html" to server filepath "/page2.html", send content of "/page2.html". Close HTTP request.

So, short version: 
External Redirect = Tell client to ask for the requested content again using a new URL and HTTP request. 
Internal Rewrite == Get content for requested URL from a different server filepath than implied by the requested URL.

The confusion over external redirects and internal rewrites is widespread; Even the Apache documentation frequently refers to "internal redirects" when internal rewrites are being discussed. And mod_rewrite, despite its name, can do internal rewrites, external redirects, or proxy through-puts, depending on the syntax of the mod_rewrite RewriteRule directive used.

转载于:https://my.oschina.net/Bruce370/blog/392830

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值