URL 重写
我在重写某个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 .htaccess 中使用此代码:
Use this code in your .htaccess:
您不能这样做 -
RewriteRule
不能直接处理查询字符串 - 只能在RewriteCond
的帮助下:我添加了
R=301 标志发出永久重定向,因此 Google 会知道旧 URL 不再使用,而应该使用新 URL。如果您不需要这样的重定向,则将其删除并仅保留
L
标志。You cannot do it this way --
RewriteRule
does not work with query string directly -- only with help ofRewriteCond
: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 leaveL
flag.