私の知る限り、「ルーティング」と「フレンドリ URL」の使用には 2 つの異なる方法があります。
1: .htaccess のみを使用:
RewriteRule ^foobar/([^/]+)/([^/]+)$ "index.php?foo=$1&bar=$2" [NC]
または 2: index.php の「ルーティング」システムと組み合わせて .htaccess を使用する:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# if file not exists
RewriteCond %{REQUEST_FILENAME} !-f
# if dir not exists
RewriteCond %{REQUEST_FILENAME} !-d
# avoid 404s of missing assets in our script
RewriteCond %{REQUEST_URI} !^.*\.(jpe?g|png|gif|css|js)$ [NC]
RewriteRule .* index.php [QSA,L]
</IfModule>
そして、index.php 内:
$uri = explode("/",substr($_SERVER['REQUEST_URI'],1));
if((isset($uri[0])) && ($uri[0]!="")) {
$page = $uri[0];
if(is_file(ROOT."/subs/docs/$page/config.php")) {
include(ROOT."/subs/docs/$page/config.php");
}
} else {
$page="home";
}
次に、行のどこかに $page を含めます。
私の質問は、どちらの方法が優れているか、または私が知らない他の方法はありますか? そして、効率、速度、およびロジックの点でより良いという意味です。