【问题标题】:htaccess + wordpress not workinghtaccess + wordpress 不工作
【发布时间】:2025-11-20 21:15:01
【问题描述】:

我正在使用更新的 WP,我正在尝试将旧网址重定向到新网址:

Redirect 301 /es/ http://www.example.com
Redirect 301 /es/tienda/ http://www.example.com
Redirect 301 /es/categoria-producto/quillas/center http://www.example.com/categoria/quillas-single/

这是我在浏览器中得到的:

如果我尝试访问第一个 URL,我会重定向到:

http://www.example.comtienda/

是的,它缺少斜线。

如果我尝试访问另一个 URL,我会重定向到:

http://www.example.com/categoria-producto/quillas/center/

这是一个 404...

所以,我迁移网站时考虑到服务器错误,但问题仍然存在......

我做错了什么?

【问题讨论】:

  • 重置您的永久链接
  • 服务器配置问题不在此处,应在 serverfault.com 上提出,但由于未显示服务器配置,您的问题也不完整。
  • @Rob 这不是服务器配置问题?!
  • @w3dk 你是说修改.htaccess文件不是服务器配置?
  • @Rob 虽然.htaccess 文件是“每个目录的 Apache 配置文件”,但它们是用户空间开发的一部分,只有在您无权访问主服务器配置时才真正需要。这将被视为 ServerFault 上的题外话,其中大多数.htaccess 问题都被关闭为一个包罗万象的问题的重复。如果您不是系统管理员并且对服务器配置具有完全访问权限,那么这种性质的任何问题在 ServerFault 上都是严格的题外话 - 唯一得到回答(而不是关闭)的是那些从网络中溜走的问题。

标签: wordpress .htaccess redirect mod-alias


【解决方案1】:
Redirect 301 /es/ http://www.example.com
Redirect 301 /es/tienda/ http://www.example.com
Redirect 301 /es/categoria-producto/quillas/center http://www.example.com/categoria/quillas-single/

由于 mod_alias Redirect 指令是前缀匹配,您需要反转这些指令。但是您缺少目标 URL 末尾的斜杠,这就是缺少斜杠的原因。所以,例如:

Redirect 301 /es/categoria-producto/quillas/center/ http://www.example.com/categoria/quillas-single/
Redirect 301 /es/tienda/ http://www.example.com/
Redirect 301 /es/ http://www.example.com/

如果源 URL 上有斜杠,则应在目标 URL 上添加斜杠。

但是,由于这是一个 WordPress 网站,您应该改用 mod_rewrite。例如,在您现有的 WP 指令之前:

RewriteRule ^es/categoria-producto/quillas/center$ /categoria/quillas-single/ [R=301,L]
RewriteRule ^es/tienda/$ / [R=301,L]
RewriteRule ^es/$ / [R=301,L]

在这种情况下,指令的顺序无关紧要。

【讨论】:

  • 谢谢@w3dk,你拯救了我的一天!
  • 我没有投票给你,伙计,你帮了我很多,我按下了“向上”按钮,但我的声望