Regex redirect URLs by removing part of it

549 Views Asked by At

I did some changes to a Wordpress site and some URLs used to come in the following format: domain.com/question-sample-url I'd like to use Yoast's Regular Expression Redirect to redirect all those domains to: domain.com/sample-url (without the question-)

Now, I've been able to redirect urls with regex that start with a phrase then * to a default URL. However, now I need to just remove one part of the phrase. Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

I don't think Yoast is capable of handling such an advanced rewrite rule. If you are using Apache2 web server, you can add this to your .htaccess file. Make sure it's above the #BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^question=(\w+)$
RewriteRule ^(.*)$ /question-%1 [L,R=301,QSD]
</IfModule>

# BEGIN WordPress
...