Sam Leurs
Sam Leurs

Reputation: 2000

Wordpress htaccess redirect with rewriterule

I have a wordpress website where I want to redirect the tag-page URL's to a specific post.

This works in .htaccess:

Redirect 301 /tag/hometrainer/ https://www.mywebsite.nl/beste-hometrainer-test

The problem is that when I append '/page/2/' (for example) to the initial url, it is also appended to the redirect url: https://www.mywebsite.nl/tag/hometrainer/page/2/ redirects to https://www.mywebsite.nl/beste-hometrainer-test/page/2, it should redirect to https://www.mywebsite.nl/beste-hometrainer-test

So I need a "catch all" for everything after "/tag/hometrainer" and this should not be displayed in the redirect url.

This does not work:

RewriteRule ^/tag/hometrainer(.*)$ /beste-hometrainer-test [R=301,L]

I get the "post not found" page.

Upvotes: 0

Views: 401

Answers (2)

phpdev
phpdev

Reputation: 179

You can try with the below code -

RewriteRule ^/from-slug(.*)$ /to-slug? [R=301,L]

Upvotes: -1

Tuan Dao
Tuan Dao

Reputation: 2805

You can add ? Add the end of URL to remove any query strings

RewriteRule ^/tag/hometrainer(.*)$ /beste-hometrainer-test? [R=301,L]

Upvotes: 0

Related Questions