既存の Web サイトを再構築し、同時に URL をよりユーザーフレンドリーな形式に書き直そうとしています。私が今持っているものhttp://example.com/test_vars.php?test_var1=value1&test_var2=value2
と、理想的には、私が欲しいものはhttp://example.com/test_vars/test_var1/value1/test_var2/value2
確かに、私は htaccess ファイルを変更するのは初めてですが、調査を行い、いくつかのことを試しました。私が探しているものに最も近いもの(確かにそれほど近くはありません)ですが、以下のコードを同封しました:
Options +FollowSymLinks
Options +Indexes
RewriteEngine on
DirectoryIndex index.html
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(([^/]+/)*[^.]+)$ /$1 [L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.html
RewriteRule .* index.html
これで、最終的に次の URL になりますhttp://example.com/test_vars.php/test_var1/value1/test_var2/value2
が、どの変数もページに渡されていません。