Htaccess rewrite ONLY if the first part of the path is numeric

Is there a htaccess rule that will be overwritten only if the first part of the path is numeric, so that http://www.example.com/123/whatever falls into the rewrite rule, but http://www.example.com / user / whatever not?

+6
.htaccess mod-rewrite
source share
2 answers

Here is a rule to rewrite my small site that I create

RewriteEngine on RewriteRule ([a-zA-Z])/ index.php?k=$1 RewriteRule ([0-9]+)/ index.php?id=$1 

So, you can see that the regexp rule [0-9] + will match any numbers in sequence. [A-zA-Z] will match the letters.

+10
source share

You can match the numbers in your template. For example:

 RewriteRule ^([0-9]+)/(.*) /foo/$2?bar=$1 

Will rewrite http://www.example.com/123/whatever in http://www.example.com/foo/whatever?bar=123 but leave / user / independently.

+4
source share

All Articles