我想在我的网站上将 /tagged/c#
映射到 /?tagged=c#
。显然,#
不会被服务器看到,所以我将其 URL 编码为 %23
。这是我正在使用的 .htaccess:
RewriteBase /
RewriteEngine On
RewriteRule ^tagged/(.*)$ /?tagged=$1 [NC]
如您所料,这有效,传递了 C#
的查询:
/?tagged=C%23
但是这些都没有,都给出了 C
/tagged/C%23
/tagged/C%23moretextthatgetslost
我假设 #
被解释为文字散列,因此在途中某处丢失了。
我需要做什么才能使这些第二种情况起作用?
最佳答案
原来我需要使用 [B]
标志:
RewriteBase /
RewriteEngine On
RewriteRule ^tagged/(.*)$ /?tagged=$1 [NC,B]
解释文档:
With the B flag, it will instead map
/C%2b%2b
to/index.php?show=/C%2b%2b
.
关于.htaccess 在 URL 中带有 `#`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10970436/