mod_rewriteルールと書き換えを処理する別の(&標準[MVC /フロントコントローラーパターン])方法は、URL全体をindex.phpに渡して、そこで処理することです。
実際には、長期的には簡単になります。そうしないと、機能を追加するときに問題の複雑さが増すだけです。
それぞれにindex.phpが含まれるフォルダー(menu|admin)
を使用しているように見えるため、ルータースクリプトの種類はありません。したがって、で基本ルートを処理する必要があります。基本的には、フォルダごとに書き直す必要があります。.htaccess
.htaccessはあなたのルートに入ります。それ以外の場合は、RewriteBase / pathを使用せずに、フォルダーごとに書き直す必要があります。
ディレクトリ構造(ルート内の.htaccessを配置する場所):
ROOT>/
/index.php
/.htaccess
/admin/
/index.php
/menu/
/index.php
/someOtherFolder/
/index.php
/somefile.php
.htaccessの書き換え
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/menu/(.*)$ admin/index.php?route=$1 [L,QSA]
RewriteRule ^menu/(.*)$ index.php?route=$1 [L,QSA]
次に、index.phpファイル内で、$_GET['route']
パラメータを次のように展開してルートを処理します。/
<?php
if(isset($_GET['route'])){
$url = explode('/',$_GET['route']);
//Assign your variables, or whatever you name them
$m = $url[0];
$o = $url[1];
$token = $url[2];
}else{
$m = null;
$o = null;
$token = null;
}
?>
それが役に立てば幸い。