如何通过RewriteRule绕过%23(哈希符号)而不丢失数据?

时间:2015-04-01 16:12:14

标签: php apache .htaccess mod-rewrite

我有以下.htaccess文件:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/command
RewriteRule .* /command/rewritehandler.php?q=%{REQUEST_URI} [B]

查看当前未回答的问题https://stackoverflow.com/questions/29376788/mod-rewrite-directives-and-valid-invalid-utf-8-characters-after-first-character的规格。 如果向服务器请求以下/aaa%23%23aa,则rewritehandler.php仅收到/aaa。看起来REQUEST_URI仅处理%23之前的数据。我应该输入什么呢?

1 个答案:

答案 0 :(得分:1)

RewriteCond捕获值,然后使用反向引用使其正常工作:

RewriteEngine On

RewriteCond %{REQUEST_URI} (.+)
RewriteRule !^command/ /command/rewritehandler.php?q=%1 [NC,B,L,QSA]