Monday , February 3 2025

301 redirect with numbers removed from URL

I have a case – for all product URLs, I need to remove numbers and dashes with a 301 redirect, for example: remove 1234- from /category/1234-product/.

Instead of 1234- there can be any numbers.

But at the same time, I don’t need to change the URL /0192-test/ in the root of the site. Here is a .htaccess mask rule that solves this problem:

RedirectMatch 301 ^/category/([0-9]+)-(.*)/$ /category/$2/

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

How to find changed files in console

Relevant for Linux, macOS. This article lists commands that help you find files that have …

Leave a Reply

Your email address will not be published. Required fields are marked *