Тема: 4images ЧПУ настройка
Нужен помощь по настройке чпу на 4images gallery.
По поиску много решении 4-5.
Самый нормальный этот.
.htaccess
RewriteEngine On
#RewriteBase /
RewriteRule ^cat-(.*)-([0-9]+)\.htm$ categories.php?cat_id=$2&%{QUERY_STRING}
RewriteRule ^cat\.htm$ categories.php?%{QUERY_STRING}
#Mod_bmollet : Image name in URL
RewriteRule ^img-(.*)-([0-9]+)\.htm$ details.php?image_id=$2&%{QUERY_STRING}
RewriteRule ^img([0-9]+)\.search.htm$ details.php?image_id=$1&%{QUERY_STRING}
RewriteRule ^img([0-9]+)\.lightbox.htm$ details.php?image_id=$1&%{QUERY_STRING}
#Mod_bmollet : This is to make search function work ( redirect links from search results )
RewriteRule ^search\.htm$ search.php?%{QUERY_STRING}
RewriteRule ^search\.([0-9]+)\.htm$ search.php?page=$1&%{QUERY_STRING}
RewriteRule ^lightbox\.htm$ lightbox.php?%{QUERY_STRING}
RewriteRule ^lightbox\.([0-9]+)\.htm$ lightbox.php?page=$1&%{QUERY_STRING}
.sessions
/* ORIGINAL CODE
function url($url, $amp = "&") {
global $l;
$dummy_array = explode("#", $url);
$url = $dummy_array[0];
if ($this->mode == "get" && !preg_match("/".SESSION_NAME."=/i", $url)) {
$url .= preg_match("/\?/", $url) ? "$amp" : "?";
$url .= SESSION_NAME."=".$this->session_id;
}
if (!empty($l)) {
$url .= preg_match("/\?/", $url) ? "$amp" : "?";
$url .= "l=".$l;
}
$url .= (isset($dummy_array[1])) ? "#".$dummy_array[1] : "";
return $url;
}
*/
function url($url, $amp = "&") {
global $l, $user_info;
$dummy_array = explode("#", $url);
$url = $dummy_array[0];
$url = str_replace('&', '&', $url);
if (!defined('IN_CP')) {
if (strstr($url, 'index.php')) {
$url = str_replace('index.php', '', $url);
}
elseif (strstr($url, 'search.php')) {
if (strstr($url, 'page=')) {
preg_match('#page=([0-9]+)&?#', $url, $matches);
if (isset($matches[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$url = str_replace('search.php', 'search.'.$matches[1].'.htm', $url);
$query = str_replace('page='.$matches[1].'&', '', $query);
$query = str_replace('&page='.$matches[1], '', $query);
$query = str_replace('page='.$matches[1], '', $query);
if (!empty($query)) {
$url .= '?' . $query;
}
}
}
else {
$url = str_replace('search.php', 'search.htm', $url);
}
}
elseif (strstr($url, 'lightbox.php')) {
if (strstr($url, 'page=')) {
preg_match('#page=([0-9]+)&?#', $url, $matches);
if (isset($matches[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$url = str_replace('lightbox.php', 'lightbox.'.$matches[1].'.htm', $url);
$query = str_replace('page='.$matches[1].'&', '', $query);
$query = str_replace('&page='.$matches[1], '', $query);
$query = str_replace('page='.$matches[1], '', $query);
if (!empty($query)) {
$url .= '?' . $query;
}
}
}
else {
$url = str_replace('lightbox.php', 'lightbox.htm', $url);
}
}
elseif (strstr($url, 'categories.php')) {
if (strstr($url, 'cat_id=') && strstr($url, 'page=')) {
preg_match('#cat_id=([0-9]+)&?#', $url, $matches1);
preg_match('#page=([0-9]+)&?#', $url, $matches2);
if (isset($matches1[1]) && isset($matches2[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$url = str_replace('categories.php', 'cat'.$matches1[1].'.'.$matches2[1].'.htm', $url);
$query = str_replace('cat_id='.$matches1[1].'&', '', $query);
$query = str_replace('&cat_id='.$matches1[1], '', $query);
$query = str_replace('cat_id='.$matches1[1], '', $query);
$query = str_replace('page='.$matches2[1].'&', '', $query);
$query = str_replace('&page='.$matches2[1], '', $query);
$query = str_replace('page='.$matches2[1], '', $query);
if (!empty($query)) {
$url .= '?' . $query;
}
}
}
elseif (strstr($url, 'cat_id=')) {
preg_match('#cat_id=([0-9]+)&?#', $url, $matches);
if (isset($matches[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$cat_url = get_category_url($matches[1]);
$url = str_replace('categories.php', 'cat'.$cat_url.'.htm', $url);
$query = str_replace('cat_id='.$matches[1].'&', '', $query);
$query = str_replace('&cat_id='.$matches[1], '', $query);
$query = str_replace('cat_id='.$matches[1], '', $query);
if (!empty($query)) {
$url .= '?' . $query;
}
}
}
else {
$url = str_replace('categories.php', 'cat.htm', $url);
}
}
elseif (strstr($url, 'details.php?image_id=')) {
if (strstr($url, 'image_id=') && strstr($url, 'mode=')) {
preg_match('#image_id=([0-9]+)&?#', $url, $matches1);
preg_match('#mode=([a-zA-Z0-9]+)&?#', $url, $matches2);
if (isset($matches1[1]) && isset($matches2[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$url = str_replace('details.php', 'img'.$matches1[1].'.'.$matches2[1].'.htm', $url);
$query = str_replace('image_id='.$matches1[1].'&', '', $query);
$query = str_replace('&image_id='.$matches1[1], '', $query);
$query = str_replace('image_id='.$matches1[1], '', $query);
$query = str_replace('mode='.$matches2[1].'&', '', $query);
$query = str_replace('&mode='.$matches2[1], '', $query);
$query = str_replace('mode='.$matches2[1], '', $query);
if (!empty($query)) {
$url .= '?' . $query;
}
}
}
else {
preg_match('#image_id=([0-9]+)&?#', $url, $matches);
if (isset($matches[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$url = str_replace('details.php', 'img'.get_image_url($matches[1]).'.htm', $url);
$query = str_replace('image_id='.$matches[1].'&', '', $query);
$query = str_replace('&image_id='.$matches[1], '', $query);
$query = str_replace('image_id='.$matches[1], '', $query);
if (!empty($query)) {
$url .= '?' . $query;
}
}
}
}
elseif (strstr($url, 'postcards.php?image_id=')) {
preg_match('#image_id=([0-9]+)&?#', $url, $matches);
if (isset($matches[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$url = str_replace('postcards.php', 'postcard.img'.$matches[1].'.htm', $url);
$query = str_replace('image_id='.$matches[1].'&', '', $query);
$query = str_replace('&image_id='.$matches[1], '', $query);
$query = str_replace('image_id='.$matches[1], '', $query);
if (!empty($query)) {
$url .= '?' . $query;
}
}
}
}
if ($this->mode == "get" && strstr($url, $this->session_id)) {
$url .= strpos($url, '?') !== false ? '&' : '?';
$url .= SESSION_NAME."=".$this->session_id;
}
if (!empty($l)) {
$url .= strpos($url, '?') ? '&' : '?';
$url .= "l=".$l;
}
$url = str_replace('&', $amp, $url);
$url .= isset($dummy_array[1]) ? "#".$dummy_array[1] : "";
return $url;
}
Last line ?>
function fixname($text)
{
return strtolower(strtr(
$text,
array(
"é" => "e",
"è" => "e",
"ê" => "e",
"à" => "a",
"ë" => "e",
"â" => "a",
"ú" => "a",
"ó" => "o",
"í" => "i",
"á" => "a",
//russian UTF8 encoded alphabet (lower and upper cases)
"А" => "a",
"а" => "a",
"Б" => "b",
"б" => "b",
"В" => "v",
"в" => "v",
"Г" => "g",
"г" => "g",
"Д" => "d",
"д" => "d",
"Е" => "e",
"е" => "e",
"Ё" => "yo",
"ё" => "yo",
"Ж" => "zh",
"ж" => "zh",
"З" => "z",
"з" => "z",
"И" => "i",
"и" => "i",
"Й" => "j",
"й" => "j",
"К" => "k",
"к" => "k",
"Л" => "l",
"л" => "l",
"М" => "m",
"м" => "m",
"Н" => "n",
"н" => "n",
"О" => "o",
"о" => "o",
"П" => "p",
"п" => "p",
"Р" => "r",
"р" => "r",
"С" => "s",
"с" => "s",
"Т" => "t",
"т" => "t",
"У" => "u",
"у" => "u",
"Ф" => "f",
"ф" => "f",
"Х" => "h",
"х" => "h",
"Ц" => "c",
"ц" => "c",
"Ч" => "ch",
"ч" => "ch",
"Ш" => "sh",
"ш" => "sh",
"Щ" => "sch",
"щ" => "sch",
"Ъ" => "",
"ъ" => "",
"Ы" => "i",
"ы" => "i",
"Ь" => "'",
"ь" => "'",
"Э" => "e",
"э" => "e",
"Ю" => "yu",
"ю" => "yu",
"Я" => "ya",
"я" => "ya",
)));
}
function get_category_url($cat_id,$cat_url = '')
{
global $site_db, $cat_cache;
static $urlname = array(); //cache names in this array
if (isset($urlname[$cat_id]))
return $urlname[$cat_id];
if (!empty($cat_cache))
{
$row['cat_name'] = @$cat_cache[$cat_id]['cat_name'];
$row['cat_parent_id'] = @$cat_cache[$cat_id]['cat_parent_id'];
}
else
{
$sql = "SELECT cat_name,cat_parent_id FROM ".CATEGORIES_TABLE." WHERE cat_id = '".$cat_id."'";
$row = $site_db->query_firstrow($sql);
}
$row['cat_name'] = fixname($row['cat_name']);
$cat_url = '-'.str_replace('+','-',urlencode($row['cat_name'])).'-'.$cat_id.$cat_url;
// if you want full path of category in url, put next line in comment
$row['cat_parent_id'] = 0;
if($row['cat_parent_id'] != 0)
{
$urlname[$cat_id] = get_category_url($row['cat_parent_id'],$cat_url);
}
else
{
$urlname[$cat_id] = $cat_url;
}
return $urlname[$cat_id];
}
//Mod_bmollet
/**
* Get the image url
* @param int $image_id The id of the image
*/
function get_image_url($image_id)
{
global $site_db;
static $urlname = array(); //cache names in this array
if (isset($urlname[$image_id]))
return $urlname[$image_id];
$sql = "SELECT cat_id,image_name FROM ".IMAGES_TABLE." WHERE image_id = '".$image_id."'";
$row = $site_db->query_firstrow($sql);
$row['image_name'] = fixname($row['image_name']);
// if you want comlpete path to image in url, remove comment from following line
//$urlname[$image_id] = get_category_url($row['cat_id']).'-'.str_replace('+','-',urlencode($row['image_name'])).'-'.$image_id;
$urlname[$image_id] = '-'.str_replace('+','-',urlencode($row['image_name'])).'-'.$image_id;
return $urlname[$image_id];
}
Категория:
_http://site.ru/cat-test-1.htm
Изображения:
1: _http://site.ru/img-ft-1.htm
2: _http://site.ru/img-test-1-ft-1.htm
Устраиваемый вид:
Категория:
_http://site.ru/test/
Изображения:
2: _http://site.ru/test/1.htm