dongwuwu6104
2013-12-20 10:47
浏览 55
已采纳

htaccess通配符仅匹配数值

I use this:

RewriteRule ^(page-a[^/]+)/?$ /page.php?a=$1

the objective is to rewrite to pages like this:

http://www.website.com/page-a47643

now how can i match only strings containing NUMBERS following "page-a" ?

The problem is that the htaccess will mess up access to folder like this:

http://www.website.com/page-about-me/

图片转代码服务由CSDN问答提供 功能建议

我用它:

  RewriteRule ^(page-a  [^ /] +)/?$ /page.php?a=$1
nn

目标是重写这样的页面: <前> http://www.website.com/page-a47643

现在如何才能匹配“页面后面包含NUMBERS的字符串” -a“?

问题是htaccess会破坏对这样的文件夹的访问:

http://www.website.com/page-about-me/

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • douxian9060 2013-12-20 10:49
    已采纳

    Change your regex to:

    RewriteRule ^(page-a[0-9]+)/?$ /page.php?a=$1 [L,QSA]
    

    [0-9]+ will match 1 or numbers and will leave /page-about-me/ as is.

    点赞 打赏 评论
  • douyuan1049 2013-12-20 10:49
    RewriteRule ^(page-a[0-9]+)/?$ /page.php?a=$1
    
    点赞 打赏 评论
  • douyue5856 2013-12-20 10:49
    RewriteRule ^(page-a\d+)/?$ /page.php?a=$1
    

    \d in Perl-compatible regular expressions (PCRE, as used by Apache) means "one digit". \d+ means "one or more digits".

    点赞 打赏 评论
  • doujingke4981 2013-12-20 10:51
    RewriteRule ^page-a([0-9]+)/?$ /page.php?a=$1 [L,QSA]
    
    点赞 打赏 评论

相关推荐 更多相似问题