开发者

Mod rewrite urls with

I'm at my wits end here , I normally like to work things out on my own but this has me well and truly beaten here.. I'm trying to mod rewrite my urls 开发者_运维知识库that contain pluses...

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

to

/can-be-any-length.html

Any help would be really appreciated becaus rewriting the + php is not an option


Using mod_rewrite for this kind of work is not the best option as you can only replace a fixed amount of characters at at time. Using PHP would certainly be easier.

But you can use the "N" (Next) flag to restart replacement, causing the rewrite engine to loop while there's a "+" in the query string:

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


Maybe with RewriteMap :

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

Content of file /path/to/file.txt

- +
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜