htaccess rewrite ONLY if first part of path is numeric
Is there开发者_运维百科 an htaccess rule that will only rewrite if the first part of a path is numeric, so that http://www.example.com/123/whatever hits the rewrite rule, but http://www.example.com/user/whatever does not?
Here is a rewrite rule for my little site I am building
RewriteEngine on
RewriteRule ([a-zA-Z])/ index.php?k=$1
RewriteRule ([0-9]+)/ index.php?id=$1
So you can see that the regex rule [0-9]+ will match any numbers successively. The [a-zA-Z] will match letters.
You can match numbers in your pattern. For example:
RewriteRule ^([0-9]+)/(.*) /foo/$2?bar=$1
Will rewrite http://www.example.com/123/whatever to http://www.example.com/foo/whatever?bar=123 but leave /user/whatever alone.
精彩评论