【问题标题】:Regex for mod rewrite用于 mod 重写的正则表达式
【发布时间】:2015-07-20 14:52:47
【问题描述】:

我需要为我的 .htaccess 文件编写正则表达式,它将用户从 test-john-doe.htmlperson.php?id=john-doe

我试过这个 RewriteRule

^test-/([a-z0-9-]+).html/$ person.php?id=$1 [R=301,L]

有人知道吗?

【问题讨论】:

  • 有很多地方可以在线测试正则表达式。您应该尝试其中一种,看看它是否能为您提供洞察力。您还可以阅读the how-to-ask guide,了解您应该在问题中包含哪些信息。

标签: regex apache .htaccess mod-rewrite


【解决方案1】:

您的正则表达式看起来有点过于复杂,试试这个:

RewriteEngine On
RewriteRule ^test-([^/]+)\.html$ /person.php?id=$1 [L]

【讨论】:

    【解决方案2】:

    你有一个额外的斜杠,你必须在正则表达式中转义点:

    RewriteRule ^test-/([a-z0-9-]+?)\.html$ person.php?id=$1 [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 2012-07-01
      • 1970-01-01
      • 2017-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-18
      • 1970-01-01
      相关资源
      最近更新 更多