Rewrite Rule To Detect Numbers Only

2020-03-02 06:40发布

I am trying to create a rewrite rule which will detect numbers only and forward them accordingly. I want the rewrite rule to be ignored if anything but numbers appears.

  • /index.php - OK
  • / - OK
  • /42365 - rewrites to view.php?id=42365

What I have so far:

RewriteEngine on
RewriteRule ^([0-9]+)?$ view.php?id=$1 [L]

1条回答
Rolldiameter
2楼-- · 2020-03-02 07:41

Remove the ? from the end of the ([0-9]+) group, which makes it optional. You must have numbers for the rewrite to occur:

RewriteEngine on
RewriteRule ^([0-9]+)$ view.php?id=$1 [L]
查看更多
登录 后发表回答