Resolved Replacing space (%20) in dynamic URL with a hyphen

Discussion in 'Web Design and Development' started by dalcorn1, Jun 15, 2011.

  1. dalcorn1, Jun 15, 2011
    Last edited: Jun 15, 2011

    dalcorn1 macrumors regular

    Joined:
    Jul 10, 2008
    #1
    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:

    in .htaccess.

    I am then linking to these pages using this code:

    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)
     
  2. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #2
    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.
     

Share This Page