.htaccess 301在wordpress中重定向子文件夹中的选择子文件夹

时间:2016-04-16 06:40:19

标签: wordpress apache .htaccess redirect http-status-code-301

问候并提前感谢您的帮助!

我正在尝试将某些子文件夹重定向到"类别"子文件夹,但不是全部。只有大约5个。

示例:

  

http://domain.com/category/fish

     

http://domain.com/category/lamb

应该重定向到

  

http://domain.com/tasty/fish

     

http://domain.com/tasty/lamb

可是:

  

http://domain.com/category/lead-paint

不应该。

我尝试过的(在.htaccess中):

 RewriteRule ^/category/fish http://example.com/tasty/fish [R=301,L]
 RewriteRule ^/category/lamb http://example.com/tasty/lamb [R=301,L]

我在Wordpress模块​​之前和之后尝试过。我也尝试插入Wordpress模块​​,如下所示:

 # BEGIN WordPress
 <IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^/category/fish http://example.com/tasty/fish [R=301,L]
  RewriteRule ^/category/lamb http://example.com/tasty/lamb [R=301,L]
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
 </IfModule>
# END WordPress

对.htaccess的更改肯定有效。 Typos生成500响应,我可以通过IP地址阻止。我不确定Wordpress是否覆盖了我的重定向,或者我是否有语法错误。

再次感谢你。

1 个答案:

答案 0 :(得分:1)

您需要在两个规则中的^之后删除前导斜杠。您也不需要指定完整域。以下将做

RewriteRule ^category/fish/?$ /tasty/fish [R=302,L]

(注意302 - 总是用临时重定向测试,然后在你开心时改为永久。)