View Full Version : friendly urls

10-26-2007, 10:35 AM

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


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:


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 "+" ?


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.

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