mod_rewrite .htaccess 重定向查询字符串的一部分

发布于 2024-10-01 20:46:07 字数 741 浏览 1 评论 0原文

我正在努力解决重定向问题。我需要使用 mod_rewrite 彻底将以下 URL 重定向到以下 .htaccess

http://www.mysite.com/somescript.php?&lang=php&var=1&var=2

到以下内容

http://www.mysite.com/somescript.php?lang=php&var=1&var=2

所以,基本上我只需要删除

&

之前的

lang=php

内容但是,顺序很重要。有时

&lang=php

出现在查询字符串中其他变量之后。在这种情况下,我需要

&

保留

&lang=php

这可能吗?

总而言之,如果 &lang=php 出现在查询字符串的开头,则删除 &。如果 &lang=php 出现在查询字符串中的其他位置,则 &必须保留。

希望这一点很清楚!

我会自己更改脚本,但不幸的是我不是开发人员,而且他目前似乎并没有太大帮助;这是一个快速修复。

I'm struggling with a redirect problem. I need to redirect the following URL with mod_rewrite thorough .htaccess

http://www.mysite.com/somescript.php?&lang=php&var=1&var=2

to the following

http://www.mysite.com/somescript.php?lang=php&var=1&var=2

So, basically I just need to remove the

&

before

lang=php

However, the order is important. Sometimes

&lang=php

appears after other variables in the querystring. in this scenario I need the

&

to remain part of

&lang=php

Is this possible?

To summarise, if &lang=php appears at the beginning of the query string, remove the &. If &lang=php appears anywhere else in the query string, the & must remain.

Hope this is clear!

I would change the script myself but unfortunately I am not the developer, and he doesn't seem too helpful at the moment; this is a quick fix.

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

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

发布评论

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

评论(2

冰雪之触 2024-10-08 20:46:08

我会将 ?& 替换为 ?

RewriteCond %{QUERY_STRING} ^\&(.*)$
RewriteRule ^somescript\.php$ /somescript.php?%1 [L,R=301]

I would replace ?& with ?:

RewriteCond %{QUERY_STRING} ^\&(.*)$
RewriteRule ^somescript\.php$ /somescript.php?%1 [L,R=301]
无法言说的痛 2024-10-08 20:46:08

为什么不匹配 "?&" 并将其替换为 "?"

像这样的东西:(

RewriteRule ^(.*)?&(.*) $1?$2 [L]

未经测试)

因为我认为组合 "?&" 永远不会有效......(?)

why don't you match "?&" and replace it by "?" ?

Something like:

RewriteRule ^(.*)?&(.*) $1?$2 [L]

(not tested)

Because I think the combination "?&" is never valid...(?)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文