Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dalcorn1

macrumors regular
Original poster
Jul 10, 2008
171
23
Hi. Found a few solutions to this but I wasn't quite sure how to implement it.

The blog I am creating uses php to create the url on a base page as standard which is called blog_single.php. I have used mod_rewrite to change the links to the pages to make them more SEO friendly so now 'root.com/blog_single.php?id=12&title=article' becomes 'root.com/blog/12/article' using this:

RewriteRule ^blog/([^/\.]+)/?/([^/\.]+)/?$ blog_single.php?id=$1&title=$2 [L]
in .htaccess.

I am then linking to these pages using this code:

<?php echo "<a href =\"blog/" .$id. "/".$title. "\">" ?><?php echo $title; ?>

The problem I have with this is that the title displays in the url with spaces 'root.com/blog/12/article%20title%20here' where as it was obviously be preferable for me to have hyphens - 'root.com/blog/12/article-title-here'. I've heard of str_replace but i have no idea how to implement this in my existing code.

Would be very grateful if someone could show me how to. Currently titles are entered into the database as they would be read, e.g. 'Article Title Here' as a bit of additional information.

(also, if someone would be so kind as to tell me how to remove the article id as from the url, i.e. 'blog/article-title-here' instead of 'blog/12/article-id-here' that would be fantastic)
 
Last edited:

jared_kipe

macrumors 68030
Dec 8, 2003
2,967
1
Seattle
If the article id number is a unique number in whatever table stores your blog posts, then you don't need the title at all.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.