使用 .htaccess 进行部分 URL 重定向

发布于 2024-09-30 06:37:36 字数 493 浏览 0 评论 0原文

我需要通过 mod_rewrite 重定向一堆 URL。 URL 结构如下:

www.mysite.com/somescript.php?&lang=asp&variable1&variable2

需要重定向到

www.mysite.com/somescript.php?&lang=php&variable1&variable2

因此,基本上,任何包含 &lang=asp 的 URL 都需要重定向到完全相同的 URL,但包含 &lang= php 替换 &lang=asp

有没有办法通过 .htaccess 来做到这一点,也许使用某种通配符?

非常感谢,我将非常感谢你的帮助。

干杯,

马特

I'm need to redirect a a bunch of URL's through mod_rewrite. The URL structure is as follows:

www.mysite.com/somescript.php?&lang=asp&variable1&variable2

Needs to redirect to

www.mysite.com/somescript.php?&lang=php&variable1&variable2

So, basically, any URL with &lang=asp in it needs to be redirected to exactly the same URL but with &lang=php replacing &lang=asp.

Is there a way I can do this through .htaccess, perhaps with some sort of wildcard?

Thanks alot, I would appreciate your help.

Cheers,

Matt

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

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

发布评论

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

评论(1

疯到世界奔溃 2024-10-07 06:37:36

修改查询字符串

访问 /path 时,将查询字符串中 val 的任何单个实例更改为 other_val。请注意,%1 和 %2 是对先前 RewriteCond 中正则表达式的匹配部分的反向引用。

RewriteCond %{QUERY_STRING} ^(.*)lang=asp(.*)$
RewriteRule /path /path?%lang=php%2

阅读此页面了解更多信息 http://wiki.apache.org/httpd/RewriteQueryString

Modifying the Query String

Change any single instance of val in the query string to other_val when accessing /path. Note that %1 and %2 are back-references to the matched part of the regular expression in the previous RewriteCond.

RewriteCond %{QUERY_STRING} ^(.*)lang=asp(.*)$
RewriteRule /path /path?%lang=php%2

Read this page for more info http://wiki.apache.org/httpd/RewriteQueryString

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