Web Hosting Talk







View Full Version : adding .html and .htm extensions to my urls


Fallzone
03-28-2005, 05:46 AM
Heya guys i need some help with my url SEO.
Im currently trying to add .html and .htm extensions to my urls.


They currently looks like this


page 1
http://www.mywebpage.com/World-of-warcraft
another page in the same category
http://www.mywebpage.com/World-of-Warcraft-50
third page in the same category
http://www.mywebpage.com/World-of-Warcraft-100


But now i would like to add .htm extensions and so far i have only succeeded to add

RewriteRule ^.+\.html$ index.php [L]
RewriteRule ^.+\.htm*$ index.php [L]

to the htaccess file and left to fix is the php code which im a total newbie at.
i would greatly appreciate if someone could take a look at it
well heres the php code for creating the current urls


<?
if(!$cid) {
//Parameters
$Param = explode("/", $_SERVER['REQUEST_URI']);
$Param = array_slice($Param, 1);
$Param = explode("-", $Param[0]);



$ParFrom = $Param[count($Param) - 1];
$Param = array_slice($Param, 0, (count($Param) - 1));
$Category = implode(" ", $Param);



preg_match("/[a-z]/", $ParFrom, $matches);
if(count($matches) > 0) {
if(strlen($Category) > 0) {
$Category .= " " . $ParFrom;
}
else {
$Category = $ParFrom;
}
}
$Category = str_replace("_", "/", $Category);
$open = mysql_connect($dbhost, $user, $pass);
$data = mysql_db_query($dbname, "SELECT * FROM top_cats WHERE catname='$Category'");
if($rad = mysql_fetch_array ($data)) {
$cid = $rad['cid'];
}
else {
$cid = 0;
}
}
if (!$from) {
if(isset($ParFrom)){
$from = $ParFrom ".html";
}
else {
$from = 0;
}

}


?>

notbrain
03-28-2005, 08:42 PM
I think you might be going about this a little backwards. In my experience with mod_rewrite, I would write all my file URLs out with .html, then use rewrite rules to convert those .html URLs into the proper .php URLs with variables passed accordingly.

I would use .html in all your links (generated from the server) and have your rewrite rules change them into the proper php URL:

/World-of-Warcraft-100.html

Then, using a rewrite rule, parse out the .html and convert the page title into the proper variable string that PHP will expect:

/World-of-Warcraft.php?display=100

(or whatever you'd call that variable).

I hesitate to write a rewrite rule to handle that off the top of my head, but I'd be glad to help if you need it.

-notbrain