2

I am in the process of turning my urls seo friendly.

My urls for my blog currently look like:

http://domain.com/news/view-article.php?id=23+category=qrops+title=moving-your-pension-abroad---what-are-the-benefits? 

How can I ensure characters like @ ? >< don't appear in my url?

How can I avoid duplicate --- ?

Code to generate the url is as follows:

<a class="small magenta awesome" title="View full article" href="view-article.php?id='.$row['id'].'+category='.strtolower($row['category']).'+title='.strtolower(str_replace(" ","-",$row['title'])).'">View full article &raquo;</a> 

Pretty sure I am doing something wrong but I'm trying...

Help appreciated..

I will move on to using the mod_rewrite in apache afterwards

2
  • possible duplicate of How to generate seo friendly url's with php? Commented Sep 24, 2011 at 13:41
  • Your URL is already SEO friendly (yes SEs deal with it nowadays). You probably mean human readable. Commented Sep 24, 2011 at 14:21

2 Answers 2

4

I used to use this function

function SEO($input){ //SEO - friendly URL String Converter //ex) this is an example -> this-is-an-example $input = str_replace("&nbsp;", " ", $input); $input = str_replace(array("'", "-"), "", $input); //remove single quote and dash $input = mb_convert_case($input, MB_CASE_LOWER, "UTF-8"); //convert to lowercase $input = preg_replace("#[^a-zA-Z]+#", "-", $input); //replace everything non an with dashes $input = preg_replace("#(-){2,}#", "$1", $input); //replace multiple dashes with one $input = trim($input, "-"); //trim dashes from beginning and end of string if any return $input; } 

For an example, you can use this by

echo "<title>".SEO($title)."</title>"; 
Sign up to request clarification or add additional context in comments.

Comments

1

I use this sweet function to generate SEO friendly URL

function url($url) { $url = preg_replace('~[^\\pL0-9_]+~u', '-', $url); $url = trim($url, "-"); $url = iconv("utf-8", "us-ascii//TRANSLIT", $url); $url = strtolower($url); $url = preg_replace('~[^-a-z0-9_]+~', '', $url); return $url; } 

4 Comments

This function is removing information which would be good to have in the search engine instead of being removed.
UTF-8 characters not part of the us-ascii pane for example. Imagine you've got non-english text (e.g. japanese) in the title. This will so break it.
@hakre: Do you have any official resources (from Google for example) what is and what isn't good, please?
Google has lots of such documented in their help system, search for webmaster resources, e.g. google.com/support/webmasters/bin/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.