Jump to content

.htaccess redirect not working


mdmartiny

Recommended Posts

I have a shortner website that I am working on. Just a little project that I am doing in hopes that i can learn better.

 

Anyways my issue is that the shortened links are not working like they should. Actually they are not working at all. I keep getting a 404 page.

 

When I do something like shortit.org/123456 I get the 404 page.

 

shortit.org is the site that I am working on.

 

Here is the redirect code

<?php 
    include('function/init.php'); 
    if(isset($_GET['code']) && !empty($_GET['code'])) {
        $code = $_GET['code'];
        redirect($code);
        die();
    }
?>

 

 

here is the redirect function

function redirect($code){
    $code = mysql_real_escape_string($code);
    if(code_exists($code)){
        $url_query = mysql_query("SELECT `url` FROM `urls` WHERE `code` = '$code'") or die (mysql_error());
        $url = mysql_result($url_query, 0 , 'url');
        header('Location:' . $url);
    }
}

 

here is my .htaccess

RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+)$ index.php?code=$1

 

Link to comment
https://forums.phpfreaks.com/topic/268634-htaccess-redirect-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.