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

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

Posted by: admin July 12, 2020 Leave a comment

Questions:

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?

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.

Thanks!

How to&Answers:

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

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

I vaguely remember that using a Location header with 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.