将mod_rewrite中的Periods / Dots /(。)重写为加号(+)

时间:2010-01-18 16:54:29

标签: regex apache mod-rewrite

如何使用mod_rewrite将句点/点(。)更改为匹配的加号(+)?我的匹配是#2

到目前为止,这是我的规则:

RewriteRule ^(.*)/(.*)-[0-9]*\.shtml$ http://kentwired.com/search/most-popular/?searchphrase=exact&searchword=$2 [L,R=301]

目前有我的规则,

http://media.www.kentnewsnet.com/media/storage/paper867/news/2009/12/11/News/Tough.Economy.Leaves.Bodies.Unburried-3850836.shtml

变为

http://kentwired.com/search/most-popular/?searchphrase=exact&searchword=Tough.Economy.Leaves.Bodies.Unburried

但我需要

http://kentwired.com/search/most-popular/?searchphrase=exact&searchword=Tough+Economy+Leaves+Bodies+Unburried

1 个答案:

答案 0 :(得分:2)

试试这个:

RewriteRule ^([^.]*)\.(.*\.shtml)$ /$1+$2 [N]
RewriteRule ^.+/([^/]+)-[0-9]*\.shtml$ http://kentwired.com/search/most-popular/?searchphrase=exact&searchword=$1 [L,R=301]