views:

855

answers:

4

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!

+2  A: 

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.

R. Bemrose
Um, it even says in the docs you linked to that using virtual() on PHP files is possible, but include() or require() are better. OP is doing it wrong.
Nathan Strong
Yes, it does, but I was answering the question that the OP asked (how to do an internal redirect). virtual() does an actual Apache subrequest for the new page, meaning that things from other languages (or compiled programs) still work.
R. Bemrose
Also, the OP said "I do not want to read/require this file from PHP..."
R. Bemrose
A: 

I would think a simple HTTP redirect would just be best, like so:

header("Location:http://somesite.com");

TravisO
A: 

My reading of the docs for header() in PHP indicates that sending a Location: header is always an EXTERNAL redirect. I didn't read anything in there about internal redirects.

bnjmnhggns
Location headers are also supposed to be fully qualified urls. I just vaguely remember in the past getting annoyed at PHP because it wasn't showing the new url in the location bar because I was only writing a partial one. At least I think it was PHP.Maybe that was with mod_rewrite stuff, though.
R. Bemrose
A: 

Thanks R. Bemrose, I think virtual() is as close to what I want to do as I'll get.

bnjmnhggns