SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict Procode's Avatar
    Join Date
    Dec 2006
    Location
    New York
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow What am I doing wrong?

    I am trying to program a URL Shortener in PHP. The domain adds to the db correctly and then shows itself correctly, but I just can't get the part where they go to the url and it redirects them to work. I keep getting a 500 internal error.

    My .htaccess:
    Code:
    XBitHack      Off
    RewriteEngine On
    RewriteCond   %{REQUEST_URI} \/([0-9a-z]{4})$ [NC]
    RewriteRule   ^(.*) http://localhost/go.php?%1 [L]
    My go.php:
    PHP Code:
    <?php

    include ("config.php");

    $i $_SERVER['QUERY_STRING'];

    if (
    preg_match("/^[0-9a-z]{6}$/"$i)) {
     
        
    $result mysql_query("SELECT short_url, url FROM `urls` WHERE `short_url` = '$i'") or die(mysql_error());
     
        if (
    mysql_num_rows($result) < 1) {
            
    header("Location: http://localhost/url");
            exit;
        }else
        {
                
    $row mysql_fetch_row($result);
            
    header("Location: ".$row[1]);
        }
     
    }

    ?>
    It is hosted on WAMP and everything seems to be good, rewrite engine is on, I'm so lost, please help!

  2. #2
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    What do you mean the domain adds to the db correctly and then shows itself? The only SQL you have is to select something from the database. You'll need to debug and find out which part of the script is causing the 500 error. Have you looked at the error logs?
    TAKE A WALK OUTSIDE YOUR MIND.

  3. #3
    SitePoint Addict Procode's Avatar
    Join Date
    Dec 2006
    Location
    New York
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JeffWalden View Post
    What do you mean the domain adds to the db correctly and then shows itself? The only SQL you have is to select something from the database. You'll need to debug and find out which part of the script is causing the 500 error. Have you looked at the error logs?
    I meant that all the other files work fine, so I know it's not a MySQL connection problem or anything.

  4. #4
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Have you had a look at the error logs to see what the output of the problem is?
    TAKE A WALK OUTSIDE YOUR MIND.

  5. #5
    SitePoint Addict Procode's Avatar
    Join Date
    Dec 2006
    Location
    New York
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Everything seems fine in the logs, I just checked and apparently the whole site is getting the internal error. I am guessing it has to be .htaccess file, because when that is removed, it works. However it doesn't redirect either.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if this will do it, but change your htaccess file from:

    RewriteCond %{REQUEST_URI} \/([0-9a-z]{4})$ [NC]
    RewriteRule ^(.*) http://localhost/go.php?%1 [L]

    to:
    RewriteCond %{REQUEST_URI} ^\/([0-9a-z]{4}) [NC]
    RewriteRule ^(.*)$ http://localhost/go.php?$1 [L]


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •