RESTful URL を処理する最も適切な方法を把握するのに苦労しています。
私は次のようなURLを持っています:
http://localhost/products
http://localhost/products/123
http://localhost/products/123/color
元は:
http://localhost/index.php?handler=products&productID=123&additional=color
今のところ、私は mod_rewrite を使用しています:
RewriteRule ^([^/]*)([/])?([^/]*)?([/])?(.*)$ /index.php?handler=$1&productID=$3&additional=$5 [L,QSA]
そして、次のような index.php でリクエストをまとめています。
if ($_GET['handler'] == 'products' && isset($_GET['productID'])) {
// get product by its id.
}
次のような 1 つの文字列として GET クエリを作成する例を見てきました。
if ($_GET['handler'] == 'products/123/color')
次に、たとえば正規表現を使用してクエリ文字列から値を取得しますか?
これは、これらの URL を処理するためのより良いアプローチですか? これらの異なるアプローチの長所と短所は何ですか? 何か良い方法はありますか?