从 localhost 重定向到 localhost/abc/ [英] redirect from localhost to localhost/abc/
问题描述
我已经在我的网站 (http://localhost
) 的根目录中放置了一个 index.php
文件.
I have placed an index.php
file in the root of my web site (http://localhost
).
我想将此页面 (http://localhost
) 重定向到 http://localhost/abc
- 当我访问 http://localhost
,我希望用户转到 http://localhost/abc
.
I want to redirect this page (http://localhost
) to http:/localhost/abc
- when I visit http://localhost
, I want the user to go to http://localhost/abc
.
我需要对我的 index.php
文件做什么?
What do I need to do to my index.php
file?
推荐答案
在你的第一个 index.php
中这样的东西怎么样:
What about something like this in your first index.php
:
header('Location: http://localhost/abc');
exit;
(顺便说一句,您在 OP ^^ 中的http:
"之后忘记了一些斜线)
(BTW, you forgot some slashes after 'http:
' in your OP ^^ )
进入第一页的任何内容/任何人都将被重定向到abc".
Anything/anyone that comes to this first page will be redirected to the 'abc' one.
有关详细信息,请参阅 header
.
See header
, for more informations.
一件事:在调用 header
函数之前确保没有任何东西被发送到输出,否则你可能会得到一个错误:如果有任何输出 (如 HTML 代码,或甚至空格!) 已经生成.
One thing : make sure nothing is send to the ouput before calling the header
function, else you might get an error : headers cannot be sent if any output (like HTML code, or even white spaces !) has already been generated.
这篇关于从 localhost 重定向到 localhost/abc/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!