views:

24

answers:

2

Hey Guys,

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

+2  A: 

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 try these rules:

RewriteCond %{QUERY_STRING} ^(([^&]*&)*)q=([^&+]*)\+([^&+]*\+.*)
RewriteRule ^ %{REQUEST_URI}?%1q=%3-%4 [N]
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)q=([^&+]*)\+([^&+]*)&*(.*)$
RewriteRule ^ /%3-%4.html?%1%5 [L,R=301]
Gumbo
Thank buddy worked a treat :)
Webby
+1  A: 

Maybe with RewriteMap :

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

Content of file /path/to/file.txt

- +
Serty Oan
Does this work for you? As far as I know there are only five different map types defined: `txt`, `rnd`, `dbm`, `int`, and `prg`.
Gumbo
You are right, I wrote it a bit quickly, sorry. Fixed it
Serty Oan