Mobile app version of vmapp.org
Login or Join
Radia820

: 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

@Radia820

Posted in: #301Redirect #Apache #Htaccess #WebDevelopment

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

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Radia820

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme