.htaccess 在 URL 中带有 `#`

标签 .htaccess mod-rewrite url-rewriting urlencode

我想在我的网站上将 /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/

相关文章:

jsp - 在 Tomcat 7 中,我可以在 <url-pattern> 中使用正则表达式吗?

使用查询参数值进行 NGINX 301 重定向

php - 如何缓存远程网页资源实现网页超速?

php - 禁用目录的 .htaccess

php - CodeIgniter - 默认 Controller 不会自动加载

.htaccess - 需要一种通用的方法来创建 SEO 友好的 URL

wordpress - 用于获取干净 URL 的 NGINX 重写规则

php - Laravel 5 - post 路由上的 htaccess HTTPS 重定向不起作用。

php - 使用 htaccess 获取值(value)和重定向

linux - Apache 重写 URI,捕获页面/文件夹