开发者

htaccess rewrite ONLY if first part of path is numeric

开发者 https://www.devze.com 2023-02-01 04:15 出处:网络
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/us

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消