开发者

Allow GET Variable Inside HTACCESS Rewrite

开发者 https://www.devze.com 2023-03-08 00:23 出处:网络
Right now I have a rewrite rule that looks like this: RewriteRule ^product-([a-z^-]+).php /sample.php?m=$1

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消