问题描述
我成功地将一个 Wordpress 站点大规模迁移到 Drupal.不幸的是,在 Wordpress 中,内容 URL 类似于 www.example.org/?p=123.我的域仍然相同,但我想通过 htaccess
进行重定向,因为 Drupal 不允许 URL 为 www.example.org/?p=123.换句话说,内容的 URL 与 Wordpress 中的 URL 不同.例如,新的 Drupal URL 将类似于 www.example.org/content/MyNewPage
I successfully mass migrated a Wordpress site to Drupal. Unfortunately in Wordpress, the content URL's were something like www.example.org/?p=123. My domain is still the same, but I want to do a redirect via htaccess
as Drupal will not allow URL's to be www.example.org/?p=123. In other words, the content does not have the same URL as it did in Wordpress. For example, the new Drupal URL would be something like www.example.org/content/MyNewPage
我在我的 .htaccess 文件中尝试了这个,但它不起作用
I tried this in my .htaccess file and it does not work
Redirect 301 /\?p=375 http://www.example.org/content/MyNewPage
所以我尝试了下面的方法,但它也不起作用.
So I tried the below, but it does not work either.
Redirect 301 /\?p\=375 http://www.example.org/content/MyNewPage
作为一个测试,我尝试了下面的方法,它奏效了.
Just as a test, I tried the below and it worked.
Redirect 301 http://www.example.org http://www.google.com
我确保我的重定向规则位于我的 .htaccess 列表的顶部,因此将首先对其进行评估.我该如何解决?
I made sure that my Redirect rule is at the top of the list in my .htaccess so it will be evaluated first. How do I fix this?
推荐答案
Redirect 和 RedirectMatch 都不允许您为重定向源指定查询字符串.[来源]
neither Redirect nor RedirectMatch allow you to specify a query string for the redirect source.[Source]
您必须使用 mod-rewrite 根据查询字符串进行重定向:
You have to use mod-rewrite for redirecting based on query string:
RewriteCond %{QUERY_STRING} ^p=375$
RewriteRule (.*) http://www.example.org/content/MyNewPage? [R=301,L]
这篇关于如何根据查询字符串重定向 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!