PDA

View Full Version : friendly urls



mucky1215
10-26-2007, 10:35 AM
Hello,

I've managed to make friendly urls, but there's a slight problem with it heres an example what i get:

http://www.gamerspot.co.uk/news_area/article/view_article/newsID/1/title/PS3%20Caused%20GTA:%20IV%20Delay!/

but as you can see, it displays the news title with "%20" which makes the url look messy. And what i want it to look like:

http://www.gamerspot.co.uk/news_area/article/view_article/newsID1/title/PS3-Caused-GTA:IV-Delay!/

And my .htaccess code looks like this:


Options +FollowSymLinks
RewriteEngine on
RewriteRule view_article/newsID/(.*)/title/(.*)/ view_article.html?newsID=$1&title=$2
RewriteRule view_article/newsID/(.*)/title/(.*) view_article.html?newsID=$1&title=$2

Is there a way that would get rid of "%20" and replace it with either "-" or "+" ?

Ben

Twey
10-26-2007, 11:14 AM
Rather than using a full version of the title, it's easier for users to remember if you "slugify" it, removing unneccessary punctuation (which also tends to look ugly in URLs):
function slugify($str) {
return strtolower(preg_replace(array('/ /', '/\W/'), array('/-/', ''), $str));
}Also, IMO, your URLs are too long. You can remove the variable names for a start, as well as having view_article be a sensible default action for articles, and end up with an URL that looks like /news_area/article/1/ps3-caused-gta-iv-delay.

mucky1215
10-26-2007, 11:24 AM
where do i put that code ?