Allow GET Variable Inside HTACCESS Rewrite
Right now I have a rewrite rule that looks like this:
RewriteRule ^product-([a-z^-]+).php /sample.php?m=$1
If I try going to "product-test.php", it works fine.
I开发者_如何学运维f I try going to "product-test.php?variable=1", it will not work.
How can I modify the rewrite rule to allow the GET variable?
NOTE: The GET variable should only allow letters (Aa-Zz) and dashes (-).
I believe it should read
RewriteRule ^product-([A-Za-z\-]+).php /sample.php?m=$1&%{QUERY_STRING}
Note the backslash escaping the dash. The dash is an operator in the matching portion, so it must be escaped.
Also, to include GET variables with a rewritten url without rewriting them, append the query string identifier to the end.
This will rewrite:
www.example.com/product-widget.php?variable=12
to
www.example.com/sample.php?m=widget&variable=12
Which is what I believe you are going for.
That having been said, I'm not sure escaping the dash actually works, as I've just discovered a problem using a dash in my rewritten urls that I can't seem to resolve. It's like the Apache 1.3.33 rewrite module doesn't like the dash in the rewrite string. Anyways, this is how it should work, and it works on my server.
精彩评论