问题原文
原帖链接 · Jeff Taylor · CC BY-SA 3.0
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.comexample.com/xyz/0001112223->example.comexample.com/foo/bar-> ignored
已采纳解答
原帖链接 · MrWhite · CC BY-SA 3.0
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
