Daniel A. White
Daniel A. White

Reputation: 190976

Rewrite Periods/Dots/(.) in mod_rewrite to plus (+)

How do I change a period/dot (.) into a plus (+) of a match using mod_rewrite? My match is #2.

This is my rule so far:

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

With my rules currently,

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

becomes

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

but I need

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

Upvotes: 2

Views: 514

Answers (1)

Gumbo
Gumbo

Reputation: 655489

Try this:

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

Upvotes: 2

Related Questions