PHPでシンプルなコントローラーを作るためにやったことのメモ
やりたいことはどんなURLでアクセスしてもindex.phpにリダイレクトさせること
.htaccessの記述
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
記述内容の説明
RewriteRule ^index\.php$ - [L]
URLの先頭がindex.phpなら置換しません
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
URLで指定されたファイルが存在しない AND
URLで指定されたファイルディレクトリが存在しないならindex.phpにリダイレクト
これで /aaa/bbb/でも/aaa/bbb/ccc.htmlでもindex.phpにリダイレクトされるようになりました。