i would like to make redirection 301 in htaccess for wordpress post to my home page
exemple work:
old post = https://www.example.com/keywordkeyworkeyword/
RedirectPermanent /keywordkeyworkeyword/ https://www.example.com
but for some articles I don't have the end of the url !
exemple no work:
old post = https://www.example.com/keywordkeyworkeywordKey...
RedirectPermanent /keywordkeyworkeywordKey(.*)$ https://www.example.com
CodePudding user response:
The RedirectPermanent
(mod_alias) directive does not take a regex, it uses simple prefix matching.
You need to use RewriteRule
(mod_rewrite) near the top of your .htaccess
, before the existing WordPress directives.
For example:
RewriteRule ^keywordkeyworkeywordKey https://www.example.com/ [QSD,R=301,L]
The above redirects any URL that starts /keywordkeyworkeywordKey
to the homepage (root URL).
Test first with a 302 (temporary) redirect to avoid caching issues. You'll need to clear your browser cache before testing.