【问题标题】:301 redirect not working in Wordpress301 重定向在 Wordpress 中不起作用
【发布时间】:2026-02-10 06:10:01
【问题描述】:

我的 .htaccess 文件中有一些重写代码。我已经将一个静态 HTML 网站移到 wordpress 中,需要以下内容才能工作:

  1. http://domain.com.au/ 重定向到http://www.domain.com.au/
  2. 重定向(旧的静态主页)index.html 到http://www.domain.com.au/

我无法工作,我已经尝试了所有建议的方法。 domain.com.au 到http://www.domain.com.au 适用于除主页之外的所有页面,例如http://domain.com.au/ourteam 重定向到 http://www.domain.com.au/ourteam

但它不会重定向到根目录(主页)。

我还收到 index.html 重定向的页面未找到错误。

我的 .htaccess 文件是:

Options +FollowSymlinks
RewriteEngine on
### re-direct index.html to root
RewriteCond %{THE_REQUEST} ^.*\/index\.html
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
### non www to www
RewriteCond %{HTTP_HOST} ^domain\.com\.au$ [NC]
RewriteRule ^(.*)$ http://www.domain.com.au/$1 [R=301,L]

redirect 301 /team.html http://www.domain.com.au/our-team/
redirect 301 /contact.html http://www.domain.com.au/contact-us/

任何人都可以帮助 - 我正在为此撕毁我的头发!

【问题讨论】:

  • 我也有类似的问题。我也尝试使用 Cpanel Redirects,然后使用一些 Wordpress 插件,然后将此代码添加到 .htaccess 但似乎没有任何效果。但是它在其他网站上也可以使用相同的代码。

标签: wordpress .htaccess


【解决方案1】:

抱歉,我刚刚遇到了这个问题,发现: Using htaccess to 301 redirect, not working

显然,您必须将重定向放在#begin wordpress 之上,因为 apache 处理重写并且永远不会到达您的重定向。

【讨论】:

    【解决方案2】:

    试试:

    <IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine on
    
    ### non www to www
    RewriteCond %{HTTP_HOST} ^domain.com.au [NC]
    RewriteRule ^(.*)$ http://www.domain.com.au/$1 [R=301,L]
    
    ### re-direct index.html to root
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
    RewriteRule ^index\.html$ http://www.domain.com.au/ [R=301,L]
    
    redirect 301 /team.html http://www.domain.com.au/our-team/
    redirect 301 /contact.html http://www.domain.com.au/contact-us/
    
    # WrodPress rules begin here...
    </IfModule>
    

    【讨论】:

      【解决方案3】:

      当您使用rewrite 规则时,您需要将 301 设置为重写格式,这是唯一可行的方法。

      RewriteRule ^/team.html$ http://www.domain.com.au/our-team/ [R=301,L]
      

      【讨论】: