Mod重写网址

时间:2010-05-28 11:15:25

标签: mod-rewrite url-rewriting

我在这里结束了我的智慧,我通常喜欢独自完成工作,但这让我很好,真的在这里打败了.. 我正在尝试修改我的包含加号的网址...

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

/can-be-any-length.html

任何帮助都会非常感激,因为重写+ php不是一个选项

2 个答案:

答案 0 :(得分:2)

使用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]

答案 1 :(得分:1)

也许使用RewriteMap:

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

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

- +