【问题标题】:Redirect URL's with index.php to wordpress default URL's doesn't work使用 index.php 将 URL 重定向到 wordpress 默认 URL 不起作用
【发布时间】:2025-12-31 12:20:21
【问题描述】:

我有问题。

我从基于 php 的网站迁移到 wordpress 系统。 旧链接是 domain.com/index.php?Subject={Value} 例如: domain.com/index.php?Subject=错误-19,domains.com/index.php?Subject=错误 domain.com/index.php?Subject=Home_Content-31 新链接是常规的 wordpress url domain.com/?p={value}

我尝试创建 htaccess,但它不起作用。 例如

Redirect 301 /index.php?Subject=Mistake-19 http://www.domain.com/?p=51  

它会将我转移到 domain.com/?Subject=Mistake-19

也试过这个:

rewriterule ^index.php?Subject=Mistake-19(.*)$ http://www.domain.com/?p=51$1 [r=301,nc]

仍然转移到 domain.com/?Subject=Mistake-19

我该如何解决?

【问题讨论】:

  • 疯狂猜测:尝试在 url 周围添加 ' '?
  • 随便试试,我只是猜测
  • :(值得一试我使用第一个示例,没有301,您可以尝试一下。怀疑它会起作用...
  • 我认为主要问题是默认的 wordpress 重定向,index.php?p=51 转移到 ?p=51。所以 /index.php?Subject=Mistake-19 自动重定向到 /?Subject=Mistake-19 并忽略 httaccess 重定向。
  • .htacces php 的敌人。如果您关闭了永久链接。 WP不会与之冲突。是不是你的第一行.htaccess?

标签: wordpress .htaccess redirect


【解决方案1】:

您必须为查询创建一个条件 (?Subject=Mistake-19) 并转义“。” (使用斜线)。

RewriteCond %{QUERY_STRING} ^Subject=Mistake-19$
RewriteRule ^index\.php?$ http://www.domain.com/?p=51? [R=301]

【讨论】: