: Htaccess to 301 redirect any URL that ends with 10 numbers How can I setup .htaccess to redirect any URL that ends with 10 digits to home? For example, I want to redirect these URLs: example.com/abc/1234567890
How can I setup .htaccess to redirect any URL that ends with 10 digits to home?
For example, I want to redirect these URLs:
example.com/abc/1234567890 -> example.com
example.com/xyz/0001112223 -> example.com
example.com/foo/bar -> ignored
More posts by @Radia820
1 Comments
Sorted by latest first Latest Oldest Best
Using mod_rewrite in .htaccess:
RewriteEngine On
RewriteRule d{10}$ / [R=301,L]
The RewriteRule pattern (regex):
- d is the shorthand character class for a digit 0-9.
- {10} is for 10 of the preceding pattern (ie. 10 digits).
- $ is an anchor for the end of the string - these digits must appear only at the end of the URL-path.
Whether you should perform a redirect like this is another matter. Multiple redirects to the homepage are likely to be seen as a soft-404 anyway.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.