user3305848
user3305848

Reputation: 15

Redirect by removing last two letters

So I been trying to figure this one out in the htaccess. I have duplicated posts looking like this:

http://test.se/bank/test-b/ http://test.se/bank/test-b-2/

I would like to redirect the posts ending with -2 to the first url.

Ive got this code so far:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^-2/(.*)$ /$1 [L,R=301]`

Upvotes: 1

Views: 32

Answers (1)

anubhava
anubhava

Reputation: 784888

Your regex is not right as you want to grab everything before -2 not after it:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^(.+?)-2$ /$1 [L,R=301]

Upvotes: 1

Related Questions