.htaccess 301 在 wordpress 中重定向子文件夹中的 select 个子文件夹
.htaccess 301 redirects in wordpress for select subfolders in a subfolder
问候并提前感谢您的帮助!
我正在尝试重定向“类别”子文件夹中的某些子文件夹,但不是全部。只有大约5个。
示例:
应该重定向到
但是:
不应该。
我尝试过的(在 .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 的更改肯定有效。拼写错误会生成 500 响应,我可以通过 IP 地址进行阻止。我不确定 Wordpress 是否覆盖了我的重定向,或者我是否有语法错误。
再次感谢。
您需要删除两个规则中 ^
之后的前导斜线。您也不需要指定完整的域。以下将做
RewriteRule ^category/fish/?$ /tasty/fish [R=302,L]
(注意 302 - 始终使用临时重定向进行测试,然后在您满意时更改为永久重定向。)
问候并提前感谢您的帮助!
我正在尝试重定向“类别”子文件夹中的某些子文件夹,但不是全部。只有大约5个。
示例:
应该重定向到
但是:
不应该。
我尝试过的(在 .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 的更改肯定有效。拼写错误会生成 500 响应,我可以通过 IP 地址进行阻止。我不确定 Wordpress 是否覆盖了我的重定向,或者我是否有语法错误。
再次感谢。
您需要删除两个规则中 ^
之后的前导斜线。您也不需要指定完整的域。以下将做
RewriteRule ^category/fish/?$ /tasty/fish [R=302,L]
(注意 302 - 始终使用临时重定向进行测试,然后在您满意时更改为永久重定向。)