【问题标题】:How do I create an Apache mod_rewrite rule that works with urlencoded values?如何创建适用于 urlencoded 值的 Apache mod_rewrite 规则?
【发布时间】:2015-01-24 07:47:28
【问题描述】:

我正在使用 php 函数 urlencode http://php.net/manual/en/function.urlencode.php 来编码一个 GET 参数 $_GET['test']

我想使用 apache 重写规则将 website.com/%CE%A6 之类的 url 重写为 website.com/index.php?test=%CE%A6

RewriteRule ^([a-z0-9])/?$ /index.php?test=$1 [NC,L]

什么是可以用来代替[a-z0-9] 以接受urlencode 函数返回的有效字符范围的正则表达式?

【问题讨论】:

    标签: php regex mod-rewrite


    【解决方案1】:

    您可以捕获任何内容,直到获得带有RewriteCond/ 以防止循环:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/?$ index.php?test=$1 [QSA,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-12
      • 1970-01-01
      • 2013-09-08
      • 1970-01-01
      • 2015-12-20
      • 1970-01-01
      • 2013-01-13
      • 2016-05-10
      相关资源
      最近更新 更多