如何删除查询字符串?

发布于 2024-10-01 18:58:18 字数 605 浏览 1 评论 0原文

注意:我不太会说英语

,我对 mod_rewrite 有疑问。

我想替换我的网站名称,我希望将此 URL

 http://www.oldsite.com/index.php?v=contact 

重写为 URL

http://www.newsite.com/page/contact with 301 rewrite.

我正在这样做:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} v=contact
RewriteRule ^index.php http://www.newsite.net/page/contact [R=301,L]

但我收到查询 http://www.newsite.net/page/contact?v=contact。 我不需要 ?v=contact,我想要 http://www.newsite.net/page/contact

Note: i little speak english

I have a problem with mod_rewrite.

I want to replace my site name, I want this URL

 http://www.oldsite.com/index.php?v=contact 

rewritten to URL

http://www.newsite.com/page/contact with 301 rewrite.

I'm doing it this way:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} v=contact
RewriteRule ^index.php http://www.newsite.net/page/contact [R=301,L]

But I'm getting the query http://www.newsite.net/page/contact?v=contact.
I dont want ?v=contact, I want http://www.newsite.net/page/contact.

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

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

发布评论

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

评论(2

梦里泪两行 2024-10-08 18:58:19

来自文档

注意:查询字符串
该模式将不会与查询字符串进行匹配。相反,您必须将 RewriteCond 与 %{QUERY_STRING} 变量结合使用。但是,您可以在替换字符串中创建包含查询字符串部分的 URL。只需在替换字符串中使用问号,即可指示以下文本应重新插入查询字符串中。 当您想要删除现有查询字符串时,只需用问号结束替换字符串。要将新查询字符串与旧查询字符串合并,请使用[QSA]标志。

所以你可能应该有:

RewriteRule ^index.php http://www.newsite.net/page/contact? [R=301,L]

From the documentation:

Note: Query String
The Pattern will not be matched against the query string. Instead, you must use a RewriteCond with the %{QUERY_STRING} variable. You can, however, create URLs in the substitution string, containing a query string part. Simply use a question mark inside the substitution string, to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine a new query string with an old one, use the [QSA] flag.

So you should probably have:

RewriteRule ^index.php http://www.newsite.net/page/contact? [R=301,L]
挽你眉间 2024-10-08 18:58:19

根据这篇文章,您应该能够编写:

RewriteRule ^index.php http://www.newsite.net/page/contact$1? [R=301,L]

According to this article, you should be able to write:

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