Forum Moderators: coopster

Message Too Old, No Replies

PHP redirect script no longer works.

         

Naveenn

8:38 am on Sep 13, 2011 (gmt 0)

10+ Year Member



I have a redirect script which I used on all the external links on my site. redirect.php?url=http://

I happned to move host and the php script no longer works, it is a simple php redirect script. The new host is running latest version of php, unlike the previous host.

Following is the script... I can no longer find the same online.


<?php

if (!isset($_GET['url']))
die('Invalid URL');

$newurl = trim(substr($_SERVER['QUERY_STRING'], 4));
if (strlen($newurl) < 1 || !preg_match('/^(ftp|http|news|https):\/\//i', $newurl))
die('Invalid URL');

$htmlurl = htmlentities($newurl);
?>

<html>
<head>
<meta http-equiv="refresh" content="0;url=<?php echo $htmlurl; ?>">
<style type="text/css"><!--
BODY {
background: #FFFFFF;
color: #000000;
}
.url {
text-decoration: underline;
color: #991111;
background: transparent;
}
.info {
text-align: center;
background: #bbbbFF;
color: #000000;
padding: 5pt 5pt 5pt 5pt;
border: 1px solid #000000;
}
--></style>
</head>
<body>
<table border="0" width="100%" height="100%">
<tr>
<td align="center" valign="middle">
<table class="info" border="0" cellspacing="0" cellpadding="2">
<tr>
<td><b>Redirecting you to the following url</b><br /><span class="url"><?php echo $htmlurl; ?></span></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>


Please help me make it work, the script is returning a 500 internal error on the new host.

penders

9:18 am on Sep 13, 2011 (gmt 0)

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



This might sound bizarre, but try a different URL param name, other than 'url'. I had a very similar problem and it was because mod_security was blocking certain URL parameter names and resulted in a 500 internal server error!?

Naveenn

10:52 am on Sep 13, 2011 (gmt 0)

10+ Year Member



This can be true because when I try to redirect the script to my own domain, it does redirect well. It is just that it wont redirect outside to external links.

Problem is that, I have already used redirect.php?url=http:// on thousands of pages and changing the url parameter will permanently break all existing links .

penders

12:00 pm on Sep 13, 2011 (gmt 0)

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



I wonder if you could do a single url rewrite in .htaccess, to avoid having to modify all your pages. Although does mod_security (if that is indeed the problem) kick in before .htaccess or after?!

Naveenn

12:07 pm on Sep 13, 2011 (gmt 0)

10+ Year Member



I am in a conversation with the host, seems like a security issue,asking them to whitelist the file.

Disabling mod_security via htaccess did not work.

Naveenn

12:33 pm on Sep 13, 2011 (gmt 0)

10+ Year Member



Ok, the same has been resolved by the host, by white listing the file.

Thank you guys!