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:

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

My go.php:


include ("config.php");


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");
            $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!

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.

Have you had a look at the error logs to see what the output of the problem is?

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.

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]

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

  1. /COLOR ↩︎