#!/usr/bin/perl -w
print "HTTP/1.1 301 Moved Permanently
Location: http://www.anothersite.com/
Content-Type: text/html; charset=UTF-8
<TITLE>301 Moved</TITLE>\n";
And it works very well when I referred to it directly www.mydomain.com/nph-script.cgi. Then I add rewriting rule like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule myscript nph-script.cgi [L,QSA]
And when I calling www.mydomain.com/myscript get the following response:
HTTP/1.1 301 Moved Permanently
Location: http://www.anothersite.com/
Content-Type: text/html; charset=UTF-8
<TITLE>301 Moved</TITLE></HEAD><BODY>
HTTP/1.1 200 OK
Date: Thu, 14 Feb 2008 16:52:49 GMT
Server: Apache/2.2.3
Content-Length: 0
Connection: close
Content-Type: text/plain; charset=UTF-8
Whats I'm doing wrong? Why Apache adds own headers after my response?
[edited by: jatar_k at 11:06 pm (utc) on Feb. 14, 2008]
[edit reason] delinked [/edit]
While it's possible that apache might add headers in some configurations (though certainly not any standard ones) if it thinks the headers aren't complete, there is no way either perl or apache would add HTML code as you show here:
<TITLE>301 Moved</TITLE></HEAD><BODY> The </head></body> can't come from nowhere so there would have to be more to your original script than you have posted.
Unless you have a server setup I've never seen before... If so it's so strange that the best way to solve your problem would probably be to switch hosts. :-)
I have luck and I discover this problem.
Apache do internal redirect when you use rewrite rule stored in .htaccess.
Just move your rule to apache config file. It make able apache to work with out redirect, and apache will able to take into account NPH rule, because all rewriting will proceed during one "session".