Forum Moderators: coopster & phranque

Message Too Old, No Replies

NPH scripts + mod rewrite = extra http headers

I'm trying to rewrite NPH scripts and get extra headers from Apache

         

Loofort

5:22 pm on Feb 14, 2008 (gmt 0)

10+ Year Member



Hello all. Need your help.
I have simple nph-script.cgi :

#!/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]

IanKelley

11:37 pm on Feb 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I suspect you're not posting the real code here.

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. :-)

IanKelley

11:39 pm on Feb 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Side note: Since all your script does is 301 to a static URL, why not just skip the extra step and create the 301 redirect in .htaccess?

Loofort

11:12 am on Feb 16, 2008 (gmt 0)

10+ Year Member



I found only one post on this forum with similar issue [webmasterworld.com...] .but it wasn't solved.

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".

Brett_Tabke

2:20 pm on Feb 18, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



or move the call higher in your htaccess order.