URL- SO . , SO Google. , SO URL, 3 URL:
- /articles/89/mytitle
/articles_en.php?artid=89 - //65/sometitle
/halls.php?fairid=65 - //65-23/
/companies.php?fairid=65&hallid=23
3 articles, halls companies :
: :
+-------+-------+
| artid | title |
+-------+-------+
:
+--------+-------+
| fairid | title |
+--------+-------+
:
+--------+--------+------+
| fairid | hallid | name |
+--------+--------+------+
3 URL- .htaccess $DOCUMENT_ROOT:
RewriteCond %{QUERY_STRING} ^artid=\d+$ [NC]
RewriteRule ^articles_en\.php/?$ router.php?handler=article [L,NC,QSA]
RewriteRule ^articles/(\d+)/?(.*)$ router.php?handler=article&artid=$1&title=$2 [L,NC,QSA]
RewriteCond %{QUERY_STRING} ^fairid=\d+$ [NC]
RewriteRule ^halls\.php/?$ router.php?handler=hall [L,NC,QSA]
RewriteRule ^halls/(\d+)/?(.*)$ router.php?handler=hall&fairid=$1&title=$2 [L,NC,QSA]
RewriteCond %{QUERY_STRING} ^fairid=\d+&hallid=\d+$ [NC]
RewriteRule ^companies\.php/?$ router.php?handler=company [L,NC,QSA]
RewriteRule ^companies/(\d+)-(\d+)/?(.*)$ router.php?handler=company&fairid=$1&hallid=$2&name=$3 [L,NC,QSA]
, router.php : ( )
<?php
$handler = mysql_real_escape_string($_GET['handler']);
switch ($handler) {
case 'article':
$artid = mysql_real_escape_string($_GET['artid']);
$title = mysql_real_escape_string($_GET['title']);
if (empty($title)) {
header("Location: /articles/$artid/" . lookupArticle($artid));
exit;
}
else
require_once("articles_en.php");
break;
case 'hall':
$fairid = mysql_real_escape_string($_GET['fairid']);
$title = mysql_real_escape_string($_GET['title']);
if (empty($title)) {
header("Location: /halls/$fairid/" . lookupHall($fairid));
exit;
}
else
require_once("halls.php");
break;
case 'company':
$fairid = mysql_real_escape_string($_GET['fairid']);
$hallid = mysql_real_escape_string($_GET['hallid']);
$name = mysql_real_escape_string($_GET['name']);
if (empty($name)) {
header("Location: /companies/$fairid-$hallid/" . lookupCompany($fairid, $hallid));
exit;
}
else
require_once("companies.php");
break;
}
function lookupArticle($artid) {
static $articles = array(89 => 'Title\ A', 90 => 'Title, 1B', 91 => '@Article= C');
return normalize($articles[$artid]);
}
function lookupHall($fairid) {
static $halls = array(65 => 'Hall+ A', 66 => 'Hall B', 67=> 'Hall C');
return normalize($halls[$fairid]);
}
function lookupCompany($fairid, $hallid) {
static $companies = array('65-23' => 'Company% A', '66-24' => 'Company B', '67-25' => '(Company) C');
return normalize($companies[$fairid .'-'. $hallid]);
}
function normalize($str) {
return preg_replace(array('#[^\pL\d\s]+#', '#\s+#'), array('', '-'), strtolower($str));
}
?>
, , 301 Moved Permanently, SEO.
PS: normalize PHP URL , .