Header Location 相对路径兼容性 [英] Header Location relative path compatibility

查看:42
本文介绍了Header Location 相对路径兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相对位置 html 标头是否与所有平台的所有浏览器完全兼容?有什么标准?

Is this relative location html header absolutely compatible with all browsers at all platforms? Any standards ?

Location: some_script.php?la=2&po=2030

我的意思是,它是否总是重定向到当前目录中的 some_script.php ?

I mean, will it always redirect to some_script.php at the current dir or not?

推荐答案

标准是这样的:

header('Location: http://www.mywebsite.com/yourpage.php?id=32', TRUE, 302);

但是要回答您的问题,是的,如果您不首先输入斜杠或完整的 URL,它将重定向到当前文件夹中的页面 X.

But to answer your question, yes it will redirect to the page X in the current folder if you don't put a slash at first or a complete URL.

这是我建议您为您所做的每个网站做的一个想法.在您的主文件(您使用的主要 php 文件,如配置或其他文件)中,创建类似的内容:

Here's an idea I would suggest you do for every website you do. In your primary file (the main php file you use like config or whatever), create something like that :

define('URL', 'http://www.mywebsite.com/');

因此,当您创建重定向、链接或其他任何内容时,请执行以下操作:

So when you create a redirection, a link or whatever, you do this :

header('Location: '.URL.'yourpage.php?id=32', TRUE, 302);

2017 年 11 月.正如下面@jordanbtucker 所指出的,HTTP 规范已于 2014 年 6 月更新(这篇文章来自 2012 年),以允许在 Location 标头中使用相对 URI.

November 2017. As pointed by @jordanbtucker below, the HTTP spec has been updated in June 2014 (this post is from 2012) to allow relative URIs in the Location header.

这篇关于Header Location 相对路径兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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