Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

php - htaccess rewrite rule with escaped ampersand in $_GET fails

I am encountering a problem with a get parameter in conjunction with a htaccess rewrite rule. Below is the urlencode()'ed link; the rewrite rule I use to redirect to index.php, and lastly, a print_r($_GET) on the index.php. As you can see, the urlescaped ampersand is not part of the value for variable static, but instead and contrary to my expectation gets interpreted as a variable seperator. Why?

Initial link:

<a href="static/Game-Tech-%26-Arts-Lab">link</a>

.htaccess:

RewriteRule ^static/(.*)$ /index.php?static=$1 [L]

index.php:

Array ( [static] => Game-Tech- [-Arts-Lab] => )
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ah, okay. Interesting. It seems there is a special solution for keeping that ampersand specifically escaped. Use the [B] flag for Rewriterules.

RewriteRule ^static/(.*)$ /index.php?static=$1 [L,B]

This is supposed to urlencode special characters when interpolating the $1 placeholder. It only works with Apache 2.2 however I believe.

Found a few references:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...