重定向.htaccess中的URL,但请保留查询字符串

发布于 2025-02-03 18:13:25 字数 576 浏览 6 评论 0原文

我想在.htaccess中重定向URL,但要在URL末尾将(Dynamic)参数从查询字符串中保留(例如?ID = 1660id = 1661等),

例如 https://mywebsite.example/service/viewinvoice.php?id = 1660

我想将其重定向到:

https://mywebsite.example.example/whmcs-bridge/? 。

​/mywebsite.example/whmcs-bridge/?ccce=viewinvoice.php?id = ...

我在下面尝试过,没有任何成功,

 RewriteEngine On

RewriteCond %{QUERY_STRING} (^|&)/service/viewinvoice.php?id= [NC]
RewriteRule ^/?$ /whmcs-bridge/?ccce=viewinvoice.php [L,R=301]

我认为这不是正确的解决方案。 有人有建议吗?

I want to redirect a URL in .htaccess, but want to keep the (dynamic) parameters from the query string at the end of the URL (e.g. ?id=1660, ?id=1661, etc.)

E.g.
https://mywebsite.example/service/viewinvoice.php?id=1660

I want to redirect it to:

https://mywebsite.example/whmcs-bridge/?ccce=viewinvoice.php?id=1660

So basically: https://mywebsite.example/service/viewinvoice.php?id=... needs to be redirected to https://mywebsite.example/whmcs-bridge/?ccce=viewinvoice.php?id=...

I tried this below, without any success

 RewriteEngine On

RewriteCond %{QUERY_STRING} (^|&)/service/viewinvoice.php?id= [NC]
RewriteRule ^/?$ /whmcs-bridge/?ccce=viewinvoice.php [L,R=301]

I think this is not the right solution.
Does someone has suggestions?

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

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

发布评论

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

评论(1

作业与我同在 2025-02-10 18:13:25

您需要使用

替换URI包含查询字符串时,重写的默认行为是丢弃现有查询字符串,并将其替换为新生成的字符串。使用[QSA]标志会导致查询字符串组合。

从示例URL中,您无需在重写条件下匹配查询字符串。您正在匹配作为重写规则本身第一部分的URL路径。

您的规则应该是:

RewriteEngine On
RewriteRule ^/?service/viewinvoice\.php$ /whmcs-bridge/?ccce=viewinvoice.php [L,R=301,QSA]

You need to use the QSA (Query String Append) flag on your rewrite rule. From the documentation:

When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.

From your example URLs, you don't need to match the query string in a rewrite condition. You are matching the URL path which is done as the first part of the rewrite rule itself.

Your rule should be:

RewriteEngine On
RewriteRule ^/?service/viewinvoice\.php$ /whmcs-bridge/?ccce=viewinvoice.php [L,R=301,QSA]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文