htaccess 隐藏部分查询字符串

发布于 2024-12-25 03:52:04 字数 963 浏览 1 评论 0原文

这是我的问题。

我想重写

www.domain.com/?cur=artist/profile&id=1&title=username -apache 读取的实际 url

www.domain.com/?cur=artist/profile&id=1&title=username - apache 读取到的

www.domain.com/username - 重写后并显示在浏览器链接上

其想法类似于 facebook

https://www.facebook.com/profile.php?id=123456789012345< /a> -在帐户设置中设置用户名之前

https://www.facebook.com/username - 设置用户名后

但就我而言,我的用户名位于查询字符串中。因此,我只需要从查询字符串 n 中删除 ?cur=artist/profile&id=1&title= ,仅留下 username

here is my issue.

i want to rewrite it

from

www.domain.com/?cur=artist/profile&id=1&title=username -actual url that apache read

to

www.domain.com/username -after rewrite and appear on browser link

the idea is similar to facebook

https://www.facebook.com/profile.php?id=123456789012345 -before set username on account setting

https://www.facebook.com/username -after set username

but in my case, i have my username on the query string. therefore, i just need to remove ?cur=artist/profile&id=1&title= from query string n left username only.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮筵 2025-01-01 03:52:04

您不能直接使用 RewriteRule 来做到这一点,您需要使用 RewriteCond。好吧,这里有两个:一个用于请求,另一个用于查询字符串。

如果 var_a 位于开头,则以下示例将有效 - 如果不是,则正则表达式将更加复杂。如果您需要更完整的答案,请完成您的问题:

RewriteCond %{REQUEST_URI} ^/index\.php$  # match "/index.php"
RewriteCond %{QUERY_STRING} ^([^=]+)=1&var_b=2 # capture "var_a" in the query string
RewriteRule .* /var_b?%1=1 [QSA] # rewrite to /var_b?var_a=1

You cannot do that using a RewriteRule directly, you need to use a RewriteCond. Well, two, here: one for the request, the other for the query string.

The following example will work, provided that var_a is at the beginning -- if it isn't, the regex will be more complicated. If you need a more complete answer, please complete your question:

RewriteCond %{REQUEST_URI} ^/index\.php$  # match "/index.php"
RewriteCond %{QUERY_STRING} ^([^=]+)=1&var_b=2 # capture "var_a" in the query string
RewriteRule .* /var_b?%1=1 [QSA] # rewrite to /var_b?var_a=1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文