私のサーバールートには、「repos」というディレクトリがあります。「server-name/repos/identifier」のようなリクエストで「repos/index.php?id=identifier」を呼び出したいと思います。ここで、identifier はユーザーが選択できるものです。
.htaccess でこれを達成するにはどうすればよいですか?
これらのルール.htaccess
は、ルート ディレクトリのファイル内に配置できます。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^repos/(.+) /repos/index.php?id=$1
これらのルールをドキュメント ルートに配置することもできます。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?repos/(.*)$ /repos/index.php?id=$1 [L,QSA]
または、ディレクトリ内の htaccess ファイルにルールを入れたい場合/repos
:
RewriteEngine On
RewriteBase /repos/
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]