Search code examples
.htaccessurlurl-rewritinghttp-redirecthttp-status-code-301

Redirect permanent string replacement


I would like the URL:

https://example.com/en/category/post+name_tour123456

To point to:

https://example.com/en/category/post+name+123456

I want to delete _tour

Can I do it with .htaccess?

I have created a regex to match all of these links:

((http[s]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([^_]+(?=_)*)(\W?_tour?)([0-9]*)

Thank you


Solution

  • So you can just match on the request. Try this rule and see how it works.

    RewriteEngine on
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /en/category/(.+)\+(.+)\+_tour(.*) [NC]
    RewriteRule ^ /en/category/%1+%2+%3 [R=301,L]