views:

49

answers:

2

I have searched left and right. And i am trying to find a script or a method on how I can store links in database and use them for redirection.

This is an E-commerce project and I am looking for something to manage Product and system URL from database.

Something Similar like magneto dose.

Basically anything after the domain say like domain.com/demo/12/my_iphone

so now demo/12/my_iphone will be sent to database for querry and in databases there will be a destination URL which could be productlisting.php?searchstring=iphones

so the user will see link domain.com/demo/12/my_iphone but actualy he will be seeing productlisting.php?searchstring=iphones

basically demo/12/my_iphone = productlisting.php?searchstring=iphones

and tomorrow if the user want to edit demo/12/my_iphone to demo/12/myiphone he can just do so using simple form which will update in the database.

How can i achieve this ?

A: 

It wouldn't be difficult to program such a solution if it comes to that. You could grab the uri from $_SERVER['REQUEST_URI'] and pass it to parse_url to grab the path. Then use the path to query against the database.

webbiedave
+1  A: 

Use mod_rewrite in apache in combination with a PHP script.

1) Make a .htaccess file and put it in a folder, say www.yourdomain.com/a/.htaccess

Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteRule .* index.php?%{QUERY_STRING} [L]

2) Create an index.php that handles all requests

(psaudo-code)

<?php
/**
 * This script is simply parsing the url used, /demo/12/my_iphone
 */
require_once('library.php');
$request_uri = $_SERVER['REQUEST_URI'];

// parse $request_uri by splitting on slashes / 
$params = my_parse_function($request_uri); // <= parse_url() is helpful here!

$param1 = $params[0]; // "demo"
$param2 = $params[1]; // "12";       
$param3 = $params[2]; // "my_iphone";

// db-lookup based on the request
$url = fetchUrlFromDB($param1, $param2, $param3);
if($url){
    header('Location: '.$url); // $url = "productlisting.php?searchstring=iphones"
    die();
}
else{
     echo "invalid parameters";
}
?>
PHP_Jedi