Vlar
Vlar

Reputation: 21

Redirect Tailing Dash in URL from Htaccess

I'm trying to 301 redirect some dash included at the end of some URLs using either mod rewrite or redirect.

There many URL affected by this structure.

http://example.com/nested/any-name-.html

to 

http://example.com/nested/any-name.html

I found this but it doesn't work with the .html at the end.

RewriteRule ^(.*)-$ http://example.com/nested/$1 [L,R=301]

Upvotes: 0

Views: 143

Answers (1)

Croises
Croises

Reputation: 18671

You can use:

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

Upvotes: 2

Related Questions