How to remove numbers from url in .htaccess?


by stephon , in category: SEO , 4 months ago

How to remove numbers from url in .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by jacey.lubowitz , 4 months ago


To remove numbers from a URL using .htaccess, you can use regular expressions and the RewriteRule directive. Here's an example of how you can achieve this:

  1. First, make sure that the Apache mod_rewrite module is enabled. You can do this by checking if the module is listed in the "Loaded Modules" section of your Apache configuration, or by running the following command in a terminal:
sudo a2enmod rewrite
sudo service apache2 restart

  1. Create or open the .htaccess file in the root directory of your website.
  2. Add the following lines to your .htaccess file:
RewriteEngine On
RewriteRule ^([a-zA-Z]+)/[0-9]+/(.*)$ /$1/$2 [R=301,L]

This rule will remove numbers from the second segment of the URL. For example, it will redirect to

  1. Save the .htaccess file and test your website to see if the numbers have been removed from the URLs.

Note: The [R=301,L] flags in the RewriteRule indicate that it should be a permanent redirect (301) and that no further rewrite rules should be processed (L).

Also, make sure to customize the regular expression (([a-zA-Z]+)) to match the specific URL structure of your website if necessary.