I was looking for a short url to use when submitting my website stories links at Twitter, I don't want to use other services as they may shutdown (or maybe hacked) at any time.
the idea is that instead of copying the full link of the story, e.g:
http://example.com/news/the-long-story-title-here
you use:
http://example.com/s11
where the 11 here is the story id.
First you need to add the following line to .htaccess file , somewhere after ##### URL Method 2 Begin #####
Code:
RewriteRule ^s([0-9]+)?$ urlshort.php?id=$1 [L]
I wrote a separate php file to get the id and redirect to the real link which should be urlshort.php:
PHP Code:
//To read DB details
include('config.php');
//DB Connect
$link = mysql_connect(EZSQL_DB_HOST, EZSQL_DB_USER, EZSQL_DB_PASSWORD)
or trigger_error("Could not connect : " . mysql_error());
mysql_select_db(EZSQL_DB_NAME) or trigger_error("Could not select database");
//Get story id passed
$story_id=mysql_real_escape_string($_GET['id']);
//Get the url title and category safe name for this ID
$query="SELECT
lnk.link_title_url, ctg.category_safe_name
FROM
pligg_links lnk LEFT JOIN pligg_categories ctg ON lnk.link_category=ctg.category_id
WHERE
lnk.link_id='".$story_id."'";
$result = mysql_query($query) or die(mysql_error());
if($row = mysql_fetch_array($result, MYSQL_ASSOC)){
header('Location: '. my_base_url .'/'.$row['category_safe_name'].'/'.$row['link_title_url']);
exit();
} else {
//To redirect to index page if no such ID
header('Location: '.my_base_url);
exit();
}
and try as given in the example above.
Notes:
- To get story id move the mouse over the vote button, and check the status bar; you should see something like this:
here it is the second number '84'.Code:javascript:vote(1,84,2,'521dc56b8da38c6eca2f77ff9b74421b',10)
- this is not fully tested, just wrote it, I'll report any issues here and if you find problems post them.






Linear Mode




