i'm running OpenCart on a lighttpd webserver. OpenCart only supports Apache and his htaccess method thats why i tried to change the seo_url in OpenCart to run on lighty also.
Why i'm doing this?
1. Problem
Lighty doesn't support rewrite checks on files or directories (files yes but not directories)
2. Problem
You need to add a seo url for every product or category. If you have many categories or products it is not doable
My Target
Using Category- and Productnames to generate SEO Urls from it. Reserved chars should be replaced. Additional database request should be avoided
Current situation
This is my rewrite for lighttpd
Code: Select all
$HTTP["host"] =~ "^(www\.)?myhost.com" {
url.rewrite-once = (
# Only for categories
".*,pc([0-9_]+)\.php$" => "/index.php?route=product/category&path=$1",
# Only for products
".*,c([0-9_]+),pp([0-9]+)\.php$" => "/index.php?route=product/product&path=$1&product_id=$2"
)
}
For example we have a product with the product id 12 and a path 12_43_630:
BIDIA© graphicscard version with 512MB, Shader 3 Model and Direct-X® 10!
We generate something like that
Code: Select all
BIDIA-graphicscard-version-with-512MB-Shader-3-Model-and-Direct-X-10,c12_43_630,pp12.php
We generate something like this:
Code: Select all
Graphicscard-BIDIA-Chip-512MB,pc12_43_630.php
Code: Select all
$replace_from = array('?', '=', ' ', '/', '&', 'ä', 'Ä', 'ö', 'Ö', 'ü', 'Ü', 'ß', '>', '<', '"', '\'', '©', '®', '.', '+', ')', '(', '[', ']', '$',',');
$replace_to = array('', '', '-', '-', '-', 'ae', 'Ae', 'oe', 'Oe', 'ue', 'Ue', 'sz', '-', '-', '', '', '', '', '', '', '', '', '', '','','');
if( isset($data['path']) && isset($data['product_id']) ) {
$sql = 'SELECT name FROM ' . DB_PREFIX . 'product_description ';
$sql .= 'WHERE product_id="' (int)$data['product_id'] . '" LIMIT 1';
$query = $this->db->query( $sql );
if( $query->num_rows ) {
$name = htmlspecialchars_decode($query->row['name']);
$name = str_replace($replace_from, $replace_to, $name );
$url = '/' . $name;
}
$url .= ',c' . $data['path'] . ',pp' . $data['product_id'] .'.php';
$url = preg_replace( '/(\-{2,})/', '-', $url );
unset($data['product_id'], $data['path']);
}
elseif( isset($data['path']) && !isset($data['product_id']) ){
$categories = explode( '_', $data['path'] );
foreach( $categories as $category ) {
$sql = 'SELECT name FROM ' . DB_PREFIX . 'category_description ';
$sql .= 'WHERE category_id="' . (int)$category . '" LIMIT 1';
$query = $this->db->query( $sql );
if( $query->num_rows ) {
$name = $query->row['name'];
$name = str_replace($replace_from, $replace_to, $name );
$url .= ( $url == '' ) ? '/' . $name: '-' . $name;
}
}
$url .= ',pc' . $data['path'] .'.php';
$url = preg_replace( '/(\-{2,})/', '-', $url );
unset($data['path']);
}
foreach ($data as $key => $value) {
if (($key == 'manufacturer_id') || ($key == 'information_id')) {
$sql = 'SELECT * FROM ' . DB_PREFIX . 'url_alias WHERE ';
$sql .= $this->db->escape($key . '=' . (int)$value);
$query = $this->db->query();
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
}
}
}
What else must be done
Caching! Something like collecting only changed or added products or categories.
What i want

What do you think about this method? Also i'm looking for some tipps about caching and the problem with the replace stuff. Would it be a good idea to add language files where people can add specific chars?
Thanks for the help and hopefully constructive advice
Disclaimer
Sorry for my bad english ^^