How to rewrite URL with Perl redirecting?

I always used the following code to redirect from a Perl script to another:

print ("Location: /path_to_destination_script/
print ("Content-type: text/html


and anytime I got the URL location rewritten in my browser.

Well, now I have moved to a new webserver and if I call the same script, the URL is not updated, it remains displaying the previous script. probably there is a different configuration in the httpd.conf of the Apache server or in the Perl configuration?

Any advice is very welcome. I need to have the URL rewritten.

Thank you in advance.

Fabrizio Ferrari

Hello Fabrizio,
You should output only the location header:

print ("Location: /path_to_destination_script/


Thank you monolitik for your kind reply. I solved the issue by writing the full URL path to the destination script including the “http://”.

Thank you for your kindness.


> I solved the issue by writing the full URL path to the
> destination script including the “http://”.
I never used Perl but Yes,
in fact the Location should be an absolute URI as stated here:

The syntax of the absoluteURI can be found here:

Using PHP will work even without the http part,
but that’s because, I think, PHP will add it automatically…

:slight_smile: Andrea

Thank you for your links Andrea, very interesting resources!

All the best,


I need to redirect URL including query string and fragment. Is this at all possible in Perl?

Need to redirect


Whatever I do I loose the ‘#section2’ part of URL.


The $ENV{“QUERY_STRING”} variable should contain the complete query.

All the best.


QUERY_STRING contains the query until the #mark. Everything after # is truncated.

Well, anyway I 've beed digging around and it seems impossible to get the fragment part of URL in Perl because it 's not passed to server.

Yes, sorry for my confusion. I tried myself and actually everything over # (included the # sign) isn’t present in any ENV variable.

I am sorry.


Why do you people need $ENV{“QUERY_STRING”} anyway? I suppose you want to use #mark to tell the browser to go to a specific part of the page, no? Browser doesn’t need Perl’s %ENV hash it will look up for the #mark part of the url automatically when loading the page.

So you do something like

print "Location: [url=""]\

and when the browser will display the resulting page, it will jump to #mark in it.

Great reply Eych! This is true.

Thank you.