我可以告诉 Apache 从 PHP 进行内部重定向吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/270117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:56:16  来源:igfitidea点击:

Can I tell Apache to do an internal redirect from PHP?

phpapacheredirect

提问by bnjmnhggns

Is there any way, from a PHP script called from mod_php with apache, to tell apache to do an INTERNAL redirect to some other file?

有什么办法可以从使用 apache 的 mod_php 调用的 PHP 脚本告诉 apache 进行内部重定向到其他文件吗?

I do not want to read/require this file from PHP and spit it out, I think it'd be more efficient to pass this off to Apache. I believe this can be done with mod_perl and I'm curious if there's a way to do it with PHP/mod_php/apache.

我不想从 PHP 读取/要求此文件并将其吐出,我认为将其传递给 Apache 会更有效。我相信这可以用 mod_perl 来完成,我很好奇是否有办法用 PHP/mod_php/apache 来做到这一点。

Thanks!

谢谢!

采纳答案by Powerlord

virtual()may do what you want. I'm not sure, I've never tried it.

virtual()可以做你想做的。我不确定,我从未尝试过。

Note that include() and require() will work if you're just calling HTML or PHP pages, plus be portable to other PHP installations.

请注意,如果您只是调用 HTML 或 PHP 页面,include() 和 require() 将起作用,并且可以移植到其他 PHP 安装。

I vaguely remember that using a Location headerwith a local url as doing an internal redirect (such as header("Location: /uri/here.php");, but I can't test it here to make sure.

我依稀记得使用带有本地 url的 Location标头进行内部重定向(例如header("Location: /uri/here.php");,但我无法在此处对其进行测试以确保。