重写规则以仅检测数字

重写规则以仅检测数字

本文介绍了重写规则以仅检测数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个重写规则,该规则将仅检测数字并相应地转发它们.我希望重写规则可以忽略,除非出现数字.

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-确定
  • /-确定
  • /42365-重写为view.php?id=42365
  • /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]

推荐答案

([0-9]+)组的末尾删除?,这使其成为可选项.您必须必须有数字才能进行重写:

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]

这篇关于重写规则以仅检测数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 08:22