Search code examples
.htaccesshttp-redirectpattern-matchingbulk

301 redirect to remove trailing hyphen


I have hundreds of duplicate pages due to a trailing - (hyphen) at the end of urls.

Now I can redirect each one separately and it works, but I'm looking for a bulk/pattern match redirect which will redirect these to save a lot of work.

http://example.co.uk/example/example- 301 redirect too http://example.co.uk/example/example

I've tried to create one with query string redirects that I know work for questions marks, but I'm having no luck.

Thanks,


Solution

  • This should do the trick:

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