【问题标题】:Mod rewrite urls withMod重写网址
【发布时间】:2012-04-20 06:15:15
【问题描述】:

我在这里束手无策,我通常喜欢自己解决问题,但这让我在这里被打败了.. 我正在尝试修改包含加号的网址...

/search.php?q=can+be+any+length

/can-be-any-length.html

任何帮助将不胜感激,因为重写 + php 不是一种选择

【问题讨论】:

    标签: mod-rewrite url-rewriting


    【解决方案1】:

    将 mod_rewrite 用于此类工作并不是最佳选择,因为您一次只能替换固定数量的字符。使用 PHP 肯定会更容易。

    但是您可以使用"N" (Next) 标志重新开始替换,导致重写引擎在查询字符串中有一个“+”时循环:

    RewriteCond %{QUERY_STRING} ^(([^&]*&)*)q=([^&+]*)\+([^&+]*\+.*)
    RewriteRule ^ %{REQUEST_URI}?%1q=%3-%4 [N]
    RewriteCond %{QUERY_STRING} ^(([^&]*&)*)q=([^&+]*)\+([^&+]*)&*(.*)$
    RewriteRule ^ /%3-%4.html?%1%5 [L,R=301]
    

    【讨论】:

      【解决方案2】:

      也许用 RewriteMap :

      RewriteMap mymap txt:/path/to/file.txt
      RewriteRule ^(.*).html$ search.php?q=${mymap:$1}
      

      文件/path/to/file.txt的内容

      - +
      

      【讨论】:

      • 这对你有用吗?据我所知,只定义了五种不同的地图类型:txtrnddbmintprg
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-29
      • 1970-01-01
      • 1970-01-01
      • 2010-10-08
      • 2018-07-31
      • 1970-01-01
      相关资源
      最近更新 更多