[HowTo] short urls for stories

Register an Account
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 03-16-2010, 08:59 PM
wesamly's Avatar
New Pligger
Pligg Version: 1.0.4
Pligg Template: arthemia
 
Join Date: Jan 2010
Location: Tripoli, Libya
Posts: 8
I am not sure if this the right place to write a HowTo?
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]
Caution: backup .htaccess file before editing
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_HOSTEZSQL_DB_USEREZSQL_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($resultMYSQL_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();

upload the php file to the main directory (where Pligg installed)
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:
    Code:
    javascript:vote(1,84,2,'521dc56b8da38c6eca2f77ff9b74421b',10)
    here it is the second number '84'.
  • this is not fully tested, just wrote it, I'll report any issues here and if you find problems post them.

My Pligg Website: http://about.ly
Reply With Quote
  #2 (permalink)  
Old 03-19-2010, 11:01 AM
Jessemn's Avatar
Casual Pligger
 
Join Date: Jun 2008
Location: Canada
Posts: 56
By including the config.php file aren't we already connecting to the DB? It would probably be easier and more modular to use the $db variable and do away with confusion of connecting and entering your username/password directly into this file (just in case it changes at some point).

Also, I think you just mean "http://example.com/11".

soLinkable - I know you're going to visit my site.
Reply With Quote
  #3 (permalink)  
Old 03-19-2010, 03:36 PM
wesamly's Avatar
New Pligger
Pligg Version: 1.0.4
Pligg Template: arthemia
 
Join Date: Jan 2010
Location: Tripoli, Libya
Posts: 8
-about the $db variable: I'll check and modify the code accordingly. Actually, when I wrote the code, I was about to publish 4 links and entries in my Twitter account so it took half an hour, it was kind of fast
in the http://example.com/s11, I used s for story, as might someone want to link to category, so he can easily replace the first letter with other choice and update the htaccess file.

Thanks a lot.

My Pligg Website: http://about.ly
Reply With Quote
Reply

Tags
short url

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Friendly URL's for categories works, but for stories not sixlaneve Questions and Comments 7 05-08-2011 11:39 PM
How can I remove the www. from the short url's? spade5702 Questions and Comments 2 12-09-2009 11:30 AM
Friendly URL's for stories And (error - Oops, what you're looking for isn't here!) roor Questions and Comments 6 07-12-2009 01:54 PM
Has anyone got Friendly Urls (Url Method 2) working? revolver Questions and Comments 11 05-08-2008 01:32 AM
Simplified Friendly Urls idea revolver Questions and Comments 0 11-07-2006 02:20 PM


Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development