- Примеры-
Пример 1. Новости вида /about/news/23.html (ссылка для печати /about/news/print_23.html) вместо /about/news/detail.php?ID=23 (/about/news/detail.php?ID=23&print=Y)
1.1 mod_rewrite
RewriteEngine On
RewriteBase /
RewriteRule ^about/news/([0-9]+).html$ about/news/detail.php?ID=$1
RewriteRule ^about/news/print_([0-9]+).html$ about/news/detail.php?ID=$1&print=Y
1.2 Обработчик 404 ошибки
[CODE]
<?
if(preg_match("~^/about/news/(print_)?([0-9]+).html$~",$_SERVER["REQUEST_URI"],$match))
{
header("HTTP/1.1 200 OK");
$_GET["print"] = (strlen($match[1])>0 ? "Y": "");
$_REQUEST["ID"] = $match[2];
include($_SERVER["DOCUMENT_ROOT"]."/about/news/detail.php");
}
else
{
define("ERROR_404", "Y");
header("HTTP/1.1 404 Not Found");
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("404 - файл не найден");
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");
}
?>
[/CODE]
Пример 2. Функция для создания идентификаторов
[CODE]
<?
function cyr_to_chpu($str)
{
$arCyr = Array("ё","й","ц","у","к","е","н","г","ш","щ","з","х","ъ","ф","ы","в","а","п","р","о","л","д","ж","э","я","ч","с","м","и","т","ь","б","ю","Ё","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","Я","Ч","С","М","И","Т","Ь","Б","Ю");
$arLat = Array("e","i","ts","u","k","e","n","g","sh","sch","z","h","","f","y","v","a","p","r","o","l","d","zh","e","ya","ch","s","m","i","t","","b","yu","e","i","ts","u","k","e","n","g","sh","sch","z","h","","f","y","v","a","p","r","o","l","d","zh","e","ya","ch","s","m","i","t","","b","yu");
$str = preg_replace("/[^a-zа-яА-Я0-9 ]/i","",$str);
$str = preg_replace("/ +/"," ",$str);
$str = str_replace($arCyr,$arLat,$str);
if(strlen($str)<=0) return "";
$str = preg_replace("/\w+/ei","ucfirst('\\0')",$str);
$str = str_replace(" ","",$str);
return $str;
}
echo cyr_to_chpu("Битрикс: управление сайтом"); //BitriksUpravlenieSaitom
?>
[/CODE]
-Смотри также-
- Module mod_rewrite URL Rewriting Engine http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
- Перевод на русский http://www.egoroff.spb.ru/portfolio/apache/mod_rewrite.html
- Еще одна статья на русском http://sitemaker.ru/technologies/webserver/mod_rewrite/
- URL Rewriting Guide http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
- Регулярные выражения http://ru2.php.net/manual/ru/reference.pcre.pattern.syntax.php
- Обработка 404 ошибки http://sitemaker.ru/technologies/webserver/error404handling/
- Директива FilesMatch http://httpd.apache.org/docs/1.3/mod/core.html#filesmatch
Пример 1. Новости вида /about/news/23.html (ссылка для печати /about/news/print_23.html) вместо /about/news/detail.php?ID=23 (/about/news/detail.php?ID=23&print=Y)
1.1 mod_rewrite
RewriteEngine On
RewriteBase /
RewriteRule ^about/news/([0-9]+).html$ about/news/detail.php?ID=$1
RewriteRule ^about/news/print_([0-9]+).html$ about/news/detail.php?ID=$1&print=Y
1.2 Обработчик 404 ошибки
[CODE]
<?
if(preg_match("~^/about/news/(print_)?([0-9]+).html$~",$_SERVER["REQUEST_URI"],$match))
{
header("HTTP/1.1 200 OK");
$_GET["print"] = (strlen($match[1])>0 ? "Y": "");
$_REQUEST["ID"] = $match[2];
include($_SERVER["DOCUMENT_ROOT"]."/about/news/detail.php");
}
else
{
define("ERROR_404", "Y");
header("HTTP/1.1 404 Not Found");
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("404 - файл не найден");
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");
}
?>
[/CODE]
Пример 2. Функция для создания идентификаторов
[CODE]
<?
function cyr_to_chpu($str)
{
$arCyr = Array("ё","й","ц","у","к","е","н","г","ш","щ","з","х","ъ","ф","ы","в","а","п","р","о","л","д","ж","э","я","ч","с","м","и","т","ь","б","ю","Ё","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","Я","Ч","С","М","И","Т","Ь","Б","Ю");
$arLat = Array("e","i","ts","u","k","e","n","g","sh","sch","z","h","","f","y","v","a","p","r","o","l","d","zh","e","ya","ch","s","m","i","t","","b","yu","e","i","ts","u","k","e","n","g","sh","sch","z","h","","f","y","v","a","p","r","o","l","d","zh","e","ya","ch","s","m","i","t","","b","yu");
$str = preg_replace("/[^a-zа-яА-Я0-9 ]/i","",$str);
$str = preg_replace("/ +/"," ",$str);
$str = str_replace($arCyr,$arLat,$str);
if(strlen($str)<=0) return "";
$str = preg_replace("/\w+/ei","ucfirst('\\0')",$str);
$str = str_replace(" ","",$str);
return $str;
}
echo cyr_to_chpu("Битрикс: управление сайтом"); //BitriksUpravlenieSaitom
?>
[/CODE]
-Смотри также-
- Module mod_rewrite URL Rewriting Engine http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
- Перевод на русский http://www.egoroff.spb.ru/portfolio/apache/mod_rewrite.html
- Еще одна статья на русском http://sitemaker.ru/technologies/webserver/mod_rewrite/
- URL Rewriting Guide http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
- Регулярные выражения http://ru2.php.net/manual/ru/reference.pcre.pattern.syntax.php
- Обработка 404 ошибки http://sitemaker.ru/technologies/webserver/error404handling/
- Директива FilesMatch http://httpd.apache.org/docs/1.3/mod/core.html#filesmatch