admin管理员组

文章数量:1317915

How can I redirect non existent pages/posts in WordPress using only .htaccess file?

Here is my code:

<IfModule mod_rewrite.c>

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^products/cool-tshirt$ /tshirts [R=301,L]

</IfModule>

Thank you in advance.

How can I redirect non existent pages/posts in WordPress using only .htaccess file?

Here is my code:

<IfModule mod_rewrite.c>

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^products/cool-tshirt$ /tshirts [R=301,L]

</IfModule>

Thank you in advance.

Share Improve this question asked May 7, 2014 at 8:02 NorotiNoroti 11 silver badge1 bronze badge 2
  • The RewriteRule directive above should already do what you require. If it's not working then you've probably put in in the wrong place - this redirect needs to go at the top of the .htaccess file, before the WordPress front-controller. If you are not using WP's permalinks (in which case you may not have WP front-controller in .htaccess) then make sure that mod_rewrite is enabled on your server. – MrWhite Commented May 24, 2018 at 11:34
  • You can just use one of redirection plug-ins. I use and like this one wordpress/plugins/nomore404-404-redirection-and-firewall It not only does redirects, but can help you block bad guys too – Ilya Polyakov Commented Oct 31, 2020 at 11:15
Add a comment  | 

1 Answer 1

Reset to default 1

This should work:

RedirectMatch 301 ^/products/cool-tshirt$ http://yourdomain/tshirts$1

You can also see a bunch of other options and solutions here

Hope this helps.

本文标签: How to redirect non existent pagesposts in wordpress using htaccess