32

この相対位置のHTML ヘッダーは、すべてのプラットフォームのすべてのブラウザーと完全に互換性がありますか? 基準はありますか?

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

つまり、常に現在のディレクトリの some_script.php にリダイレクトされるのでしょうか?

4

1 に答える 1

33

The standard would be this:

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

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.

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);

EDIT: 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.

于 2012-05-10T20:15:54.093 に答える