【问题标题】:How to merge these url rewrite rules together?如何将这些 url 重写规则合并在一起?
【发布时间】:2015-01-09 03:53:49
【问题描述】:

我在 .htaccess 文件中使用这 3 条规则来重写 url,它们运行良好。但我认为这 3 条规则可以合并为 1 条规则。有人可以告诉我该怎么做吗?由于我是正则表达式的新手,因此我将不胜感激:)

RewriteRule ^index.htm$       news/index.htm
RewriteRule ^news/$           news/index.htm
RewriteRule ^news/([0-9]+)$   news/index_$1.htm

【问题讨论】:

    标签: regex .htaccess mod-rewrite


    【解决方案1】:

    您可以将其中两个合并为一个规则,但最后一个需要分开:

    RewriteRule ^(index\.htm|news/)$ news/index.htm [L]
    RewriteRule ^news/([0-9]+)$   news/index_$1.htm [L]
    

    【讨论】:

      猜你喜欢
      • 2012-09-27
      • 1970-01-01
      • 2020-04-11
      • 1970-01-01
      • 1970-01-01
      • 2013-01-23
      • 1970-01-01
      • 1970-01-01
      • 2012-05-03
      相关资源
      最近更新 更多