URL 重写

发布于 2024-12-25 06:15:01 字数 296 浏览 0 评论 0原文

我在重写某个 URL 时遇到问题。

我正在做一些网站迁移,Google 的索引中仍然有一些旧的 URL,我想将其重定向到新页面。我在想,在对查询字符串进行查询字符串剥离并重定向之前,我想知道您是否可以先在 mod_rewrite 中完成此操作?目前我的 .htaccess 中有这个,但它不起作用。

RewriteRule ^news.php?action=view&title=(.*) /blog.php?article_keyword=$1 [L]

环境是Linux+Apache

I am having trouble with my rewriting of a certain URL.

I am doing some site moving and Google still has some old URLs in its index that it crawls that I would like to redirect to the new page. I was thinking before I do a query string strip on the query strings and redirect, I was wondering if you can accomplish this in mod_rewrite first? I currently have this in my .htaccess but it doesn't work.

RewriteRule ^news.php?action=view&title=(.*) /blog.php?article_keyword=$1 [L]

The environment is Linux with Apache

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

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

发布评论

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

评论(2

内心旳酸楚 2025-01-01 06:15:01

在 .htaccess 中使用此代码:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} ^action=view&title=(.*)$ [NC]
RewriteRule ^news\.php/?$ /blog.php?article_keyword=%1 [L,R=301,NC]

Use this code in your .htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} ^action=view&title=(.*)$ [NC]
RewriteRule ^news\.php/?$ /blog.php?article_keyword=%1 [L,R=301,NC]
清醇 2025-01-01 06:15:01

您不能这样做 - RewriteRule 不能直接处理查询字符串 - 只能在 RewriteCond 的帮助下:

RewriteCond %{QUERY_STRING} ^action=view&title=(.*)
RewriteRule ^news.php$ /blog.php?article_keyword=%1 [R=301,L]

我添加了 R=301 标志发出永久重定向,因此 Google 会知道旧 URL 不再使用,而应该使用新 URL。如果您不需要这样的重定向,则将其删除并仅保留 L 标志。

You cannot do it this way -- RewriteRule does not work with query string directly -- only with help of RewriteCond:

RewriteCond %{QUERY_STRING} ^action=view&title=(.*)
RewriteRule ^news.php$ /blog.php?article_keyword=%1 [R=301,L]

I've added R=301 flag to issue permanent redirect, so Google will know that old URL is no longer in use and it should use new URL instead. If you do not need such redirect, then rmove it and only leave L flag.

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