A PHP equivalent of Server.Transfer?

A question from comp.lang.php:

In ASP.NET there is a method called Server.Transfer which transfers the request to a different page from the one that the user requested, but without doing a redirect. The user gets sent headers as though they were seeing the page they requested.

Does PHP have such a function?

No. Server.Transfer is IIS’ way of doing URL rewriting. PHP, being originally developed for Apache, leaves URL rewriting to the HTTP server. So what you need to do is to set up a rewrite rule. If you are using Apache, you already have everything you need for that. If you are using IIS, there are add-on modules that allow you to do URL rewriting. I use ISAPI_Rewrite on one of my development servers:

http://www.isapirewrite.com/

From your later message, I understand you are using WordPress. WordPress’ .htaccess file is not very complicated; it basically boils down to this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

and the above in all likelihood can be ported over to ISAPI_Rewrite.

Leave a Reply

Your email address will not be published. Required fields are marked *