PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Nov 27, 2014 5:27 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: friendly links
PostPosted: Thu Jun 14, 2012 7:30 am 
Offline
Forum Commoner

Joined: Sat Nov 10, 2007 9:03 am
Posts: 25
Hello,

I have link in my site like:
<a href="index.php?page=article&title=title-something&id=1234">blabla</a>

I want to use in my site friendly links like:
<a href="title-something-1234">blabla</a>

Where "title-something" is a title from an article and "1234" it's his ID.
How can I change the htaccess file in order if I click on that link to show that article but to make the mysql select query by ID ?

Thanks


Top
 Profile  
 
 Post subject: Re: friendly links
PostPosted: Thu Jun 14, 2012 2:27 pm 
Offline
Forum Contributor
User avatar

Joined: Thu May 11, 2006 8:58 pm
Posts: 305
Location: Utah, USA
Syntax: [ Download ] [ Hide ]
RewriteEngine On
RewriteRule ^(.+)-([0-9]+)$ index.php?page=article&title=$1&id=$2 [QSA,L]
# OR if you might have other types of URLs that end with dash and numbers:
RewriteRule ^article/(.+)-([0-9]+)$ index.php?page=article&title=$1&id=$2 [QSA,L]


Top
 Profile  
 
 Post subject: Re: friendly links
PostPosted: Thu Jun 14, 2012 2:43 pm 
Offline
Forum Commoner

Joined: Sat Nov 10, 2007 9:03 am
Posts: 25
Thanks, but I need to complete htaccess for this kind of link:
<a href="title-something-1234">blabla</a>


Top
 Profile  
 
 Post subject: Re: friendly links
PostPosted: Fri Jun 15, 2012 12:32 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 5658
Location: WA, USA
Are you saying tr0gd0rr's code doesn't work? Because it does.


Top
 Profile  
 
 Post subject: Re: friendly links
PostPosted: Fri Jun 15, 2012 2:46 am 
Offline
Forum Commoner

Joined: Sat Nov 10, 2007 9:03 am
Posts: 25
It does, but only if I set the link like: <a href="tablouri_det/title-'.$id.'" >

I want to set the link like: <a href="title-'.$id.'" > . If I use in this way with the code for htaccess sent by tr0gd0rr, it doesn't work. Somehow I need to hide the page from the link.


Top
 Profile  
 
 Post subject: Re: friendly links
PostPosted: Fri Jun 15, 2012 8:24 am 
Offline
Forum Commoner

Joined: Sat Nov 10, 2007 9:03 am
Posts: 25
I get it, it's ok.
But now I have:
RewriteRule ^(.+)-([0-9]+)$ index.php?page=tablouri_det&title=$1&id_tab=$2 [QSA,L]
RewriteRule ^(.+)-([0-9]+)$ index.php?page=tablouri&title=$1&id_tab=$2 [QSA,L]

And the link is: <a href="title-'.$id.'" >. Obviously is not working because he don't know what rule should take. Can can I use this link without showing the page ?


Top
 Profile  
 
 Post subject: Re: friendly links
PostPosted: Fri Jun 15, 2012 12:43 pm 
Offline
Forum Contributor
User avatar

Joined: Thu May 11, 2006 8:58 pm
Posts: 305
Location: Utah, USA
Do you have some other rewrite rules? They may be triggering first.


Top
 Profile  
 
 Post subject: Re: friendly links
PostPosted: Fri Jun 15, 2012 1:49 pm 
Offline
Forum Commoner

Joined: Sat Nov 10, 2007 9:03 am
Posts: 25
RewriteEngine on
RewriteRule ^sitemap/.*$ - [PT]
RewriteRule ^administrator/.*$ - [PT]
RewriteRule ^temp/.*$ - [PT]
ErrorDocument 404 /http://www.picturi-celebre.ro

RewriteRule ^picturi~(.+)~(.+)~([0-9]+)$ index.php?page=picturi&filtru=$1&tip=$2&gal=$3 [QSA,L]
RewriteRule ^(.+)-([0-9]+)$ index.php?page=tablouri_det&title=$1&id_tab=$2 [QSA,L]
RewriteRule ^contact$ index.php?page=contact [QSA,L]
RewriteRule ^account$ index.php?page=account [QSA,L]
RewriteRule ^artisti~([0-9]+)$ index.php?page=artisti&gal=$1 [QSA,L]
RewriteRule ^promotii~([0-9]+)$ index.php?page=picturi&filtru=promotii&gal=$1 [QSA,L]
RewriteRule ^expozitie-de-picturi$ index.php?page=expozitie-de-picturi [QSA,L]
RewriteRule ^expozitie-de-picturi~(.+)$ index.php?page=expozitie-de-picturi&id_tab=$1 [QSA,L]


Top
 Profile  
 
 Post subject: Re: friendly links
PostPosted: Tue Jun 19, 2012 2:20 pm 
Offline
Forum Contributor
User avatar

Joined: Thu May 11, 2006 8:58 pm
Posts: 305
Location: Utah, USA
Those look ok. Are you sure you don't have more rewrite rules in parent or child folders?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group