forms - Mod rewrite test.php?p=one to test/one -


i rewrite rules site.com/product/p1 site.com/product.php?p=p1 successfully.

now, want the opposite, convert query received form submission site.com/product.php?id=1234&name=test site.com/product/test/1234 i.e. don't want site visitor see query parameters.

to make things more clear: on site have form 2 text input fields (and few hidden fields well); visitors can enter product id , product name , submit form. want resulting url (after form submission) flat (site.com/product/test/1234) , not include params.

of course, want script (product.php) retrieve parameters form. guess in same fashion turn site.com/product/p1 site.com/product.php?p=p1.

could me out?

mod_rewrite not flexible enough in general. it's fine when have 1 (and one) query parameter handle. add more, need handle every possible combination of query parameters, , have new rule each. mod_rewrite appropriate if can no longer serve urls in old style, example if upgrading third-party server cannot modify, , want have httpd handle redirecting old bookmarked links new locations.

it best handle inside php script itself. script @ "old" product.php?id=1234&name=test url should read get parameters , return http 301 response ("moved permanently") new product/test/1234 url. work if request goes product.php, or product.php?name=test, or product.php?id=1234, or product.php?name=test&id=1234. script determines missing values, , how build replacement url.

to rewrite single query parameter, reverse of successful rewrite rule, e.g.

rewritecond     %{query_string}    ^p=(.*)$ rewriterule     /product.php       /product/%1   [r] 

Comments