Redirect script not working with new host

Discussion in 'PHP' started by TechDesigner, Sep 13, 2011.

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

    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>
    
    PHP:
    Please help me make it work, the script is returning a 500 internal error on the new host.
     
    TechDesigner, Sep 13, 2011 IP
  2. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #2
    seems to be no issues on you script, maybe you can ask your new host why error 500 is happening.

    is it happening on this script only?
     
    JohnnySchultz, Sep 13, 2011 IP
  3. yank whalley

    yank whalley Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    use .htaccess if you write the code in php
     
    yank whalley, Sep 13, 2011 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    More then likely a .htaccess problem

    You might need to to add or remove the following:
    RewriteBase /
    Code (markup):
    EDIT: as above post...
     
    MyVodaFone, Sep 13, 2011 IP
  5. TechDesigner

    TechDesigner Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The htaccess did not help. Can this be a security issue?

    I tried to redirect the script to my own domain and it does redirect. It will not redirect to external links only.
     
    TechDesigner, Sep 13, 2011 IP
  6. TechDesigner

    TechDesigner Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It (500) seems to be happening to few other scripts also but I was able to work around it, not all scripts are affected.
     
    TechDesigner, Sep 13, 2011 IP
  7. TechDesigner

    TechDesigner Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Ok, the same has been resolved by the host, by white listing the file.

    Thank you guys!
     
    TechDesigner, Sep 13, 2011 IP
  8. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #8
    500 is a server error, it doesn't tell you what server error. You'll have to get your providerr's tech support involved, so they can look in the server error log and tell you what the error is. If it's an Apacjhe server, t'll be in the form of

    [Tue Sep 13 09:59:36 2011] [error] [client 1.2.3.4] PHP Parse error: syntax error, [some problem] in C:\\Apache2.2\\htdocs\\[some file].php on line [some line], referer: [some file]


    You need the [some problem], [some file] and [some line] parts to determine where the problem is. Then you look at that line in that file (it'll probably be your redirect script) to see where the error is. The script seems to run fine in PHP 5.2.6 on an Apache 2 server.
     
    Rukbat, Sep 13, 2011 IP