admin管理员组文章数量:1287561
Wordpress automatically generates category pages, for example: /
I want to redirect this to a custom page, for example: /
What's the simplest way to do this?
I tried this (I suspect this is overcomplicated):
RewriteEngine on
RewriteBase /
RewriteRule ^category/microgreens/recommended-equipment/(.*) /$1 [R=301,L]
And if I want to do multiple does something like the following make sense? Or is there redundancy and I don't need to turn RewriteEngine on for each redirect?
RewriteEngine on
RewriteBase /
RewriteRule ^category/microgreens/recommended-equipment/(.*) /$1 [R=301,L]
RewriteEngine on
RewriteBase /
RewriteRule ^category/microgreens/growing/(.*) /$1 [R=301,L]
etc...
This code is currently not working on my site. I've cleared my wordpress cache, and I'm running Ezoic, I've also cleared my Ezoic cache.
I've also tried putting the following in .htaccess and it doesn't work:
RedirectPermanent / /
Thanks!
Wordpress automatically generates category pages, for example: https://planthardware/category/microgreens/recommended-equipment/
I want to redirect this to a custom page, for example: https://planthardware/microgreens-equipment/
What's the simplest way to do this?
I tried this (I suspect this is overcomplicated):
RewriteEngine on
RewriteBase /
RewriteRule ^category/microgreens/recommended-equipment/(.*) https://www.planthardware/microgreens-equipment/$1 [R=301,L]
And if I want to do multiple does something like the following make sense? Or is there redundancy and I don't need to turn RewriteEngine on for each redirect?
RewriteEngine on
RewriteBase /
RewriteRule ^category/microgreens/recommended-equipment/(.*) https://www.planthardware/microgreens-equipment/$1 [R=301,L]
RewriteEngine on
RewriteBase /
RewriteRule ^category/microgreens/growing/(.*) https://www.planthardware/microgreens-growing/$1 [R=301,L]
etc...
This code is currently not working on my site. I've cleared my wordpress cache, and I'm running Ezoic, I've also cleared my Ezoic cache.
I've also tried putting the following in .htaccess and it doesn't work:
RedirectPermanent https://www.planthardware/category/microgreens/recommended-equipment/ https://www.planthardware/microgreens-equipment/
Thanks!
Share Improve this question edited Oct 13, 2021 at 17:04 Turillian asked Oct 13, 2021 at 16:11 TurillianTurillian 135 bronze badges 19 | Show 14 more comments1 Answer
Reset to default 0Once you have found the right .htaccess
file in the document root (ie. inside the public_html
directory) then these redirect directives need to go at the top of the .htaccess
file, before the existing WordPress directives. ie. Before the # BEGIN WordPress
section.
You do not need to repeat the RewriteEngine
or RewriteBase
directives. (The RewriteBase
directive is not actually being used here anyway.) The RewriteEngine On
directive appears later in the file (inside the WordPress block), you do not need to repeat this.
To redirect as required you just need the following:
RewriteRule ^category/microgreens/recommended-equipment/ https://www.planthardware/microgreens-equipment/ [R=301,L]
You do not need the capturing subpattern (.*)
and corresponding $1
backreference to redirect the example URL as stated.
NB: Test with 302 (temporary) redirect first to avoid potential caching issues.
If you are redirecting to the same scheme and hostname, you do not need to repeat these in the target URL. For example:
RewriteRule ^category/microgreens/recommended-equipment/ /microgreens-equipment/ [R=301,L]
You can use capturing subpatterns and backreferences to avoid repetition. For example:
RewriteRule ^category/(microgreens)/recommended-(equipment)/ /$1-$2/ [R=301,L]
The $1
backreference contains "microgreens" from the first capturing group (parenthesised subpattern) and $2
contains "equipment" from the second.
UPDATE: And for the second redirect you could write it like this (using backreferences):
RewriteRule ^category/(microgreens)/(growing)/ /$1-$2/ [R=301,L]
To redirect to /microgreens-growing/
.
Aside:
I've also tried putting the following in .htaccess and it doesn't work:
RedirectPermanent https://www.planthardware/category/microgreens/recommended-equipment/ https://www.planthardware/microgreens-equipment/
Note that the RedirectPermanent
directive belongs to mod_alias (as opposed to mod_rewrite RewriteRule
), consequently it runs much later, after all the other mod_rewrite directives, despite the apparent order of the directives in the config file. For this reason, it is advisable not to mix redirects from both modules, since you can get unexpected conflicts.
Note that the RedirectPermanent
directive matches against the root relative URL-path (starting with a slash), not the absolute URL. So, the above directive wouldn't match anyway. It should be written like this instead:
RedirectPermanent /category/microgreens/recommended-equipment/ https://www.planthardware/microgreens-equipment/
OR (omitting the scheme + hostname on the target URL):
RedirectPermanent /category/microgreens/recommended-equipment/ /microgreens-equipment/
本文标签: categoriesWordpress category page redirects in htaccess not working
版权声明:本文标题:categories - Wordpress category page redirects in .htaccess not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741272804a2369561.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
.htaccess
file are you adding these directives? You appear to be trying to match something at the end of the URL (and passing this through to the target) - but this is not stated in your example? – MrWhite Commented Oct 13, 2021 at 16:55