Create url for mod_rewrite

Creating urls with Search engine optimized keywords from database records involves more than just mod_rewrite and htaccess synchronization. The first step of a good search engine indexing strategy is to take one of your database fields as index (title is a good one) , transform it by removing spaces, special characters, and if necessary append record unique identifier to the generated string. Here is a sample function that transforms a string to make it file compliant using a regular expression to discard non alphanumeric characters and replace spaces with dashes :

function make_url($string){

$pattern = "([^[[:alnum:]|[:space:]|[:blank:]])+";
$anchor = ereg_replace($pattern, '', strtolower($string));
$pattern = "([[:space:]]|[[:blank:]])+";
$anchor = ereg_replace($pattern, '-', $anchor);
return short_name($anchor); // return the short filtered name
} # end function

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *