如果存在查询字符串值,如何重定向请求?

发布于 2024-09-14 21:42:34 字数 452 浏览 2 评论 0原文

我搜索并尝试了很多例子,但似乎没有一个对我有用。我需要将请求重定向到特定的 url,具体取决于原始请求的查询字符串中是否包含某个项目。

例如

www.mydomain.com/test.html?username=foo&password=bar

因此,我只想将查询字符串中存在的用户名变量重定向到

www.mydomain.com/home.html?username=foo& 因此,

另外,该页面可以是任何页面,例如 test.html、home.html、contact.php

如果在查询字符串中检测到用户名变量,则只会发生重定向。

感谢您的帮助。

我尝试了这个,但它不起作用:

RewriteRule ^username(.*)$ test.html?username=$1 [L,QSA]

I've searched and tried many examples but none seem to work for me. I need to redirect a request to a specific url depending on if the original request had a certain item in it's query string.

e.g.

www.mydomain.com/test.html?username=foo&password=bar

So I want to redirect this only is the username variable is present in the query string to

www.mydomain.com/home.html?username=foo&password=bar

But also, the page could be any page, .e.g test.html, home.html, contact.php

So if username variable is detected in query string, then the redirect will happen only.

thanks for your help.

I tried this but it did not work:

RewriteRule ^username(.*)$ test.html?username=$1 [L,QSA]

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

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

发布评论

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

评论(1

走过海棠暮 2024-09-21 21:42:34

您可以使用 QUERY_STRING 来完成此操作。

RewriteCond %{QUERY_STRING} username
RewriteCond %{REQUEST_URI} !^/home.html
RewriteRule .* /home.html/ [L,QSA]

You can use QUERY_STRING to accomplish this.

RewriteCond %{QUERY_STRING} username
RewriteCond %{REQUEST_URI} !^/home.html
RewriteRule .* /home.html/ [L,QSA]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文