Unfortunately I’ll go back to PHP redirect method, as an .htaccess redirect encodes utf-8 characters in the URL which does not look good in the browser’s address bar.
Any other thoughts and advices about this matter still appreciated
Well I found a way to unescape the utf-8 characters in the query string with RewriteMap directive, but it seems that RewriteMap is not allowed in .htaccess unfortunately.
So I still have the PHP redirect based solution which would use more resources
Hmmm, your rewrite code looks okay to me but your form isn’t directing to search?q={whatever}. What’s up with that?
I’m sure you’ve been through this before but YOU create the “new format” links and then YOU create the mod_rewrite code to redirect that to the “serve-able” script. The form redirects (with a valid action), to search.php?q={whatever}.
Almost. I meant that action of searchrd means NOTHING and does not match your regex anyway. Basically, using a form, you’re stuck with the search.php?q={whatever} which will automatically escape characters in the {whatever} value.
Yes, but when I do not use htaccess redirect, escaped utf-8 chars are displayed as letters in the address bar of modern browsers. On the other hand the mod_rewrite-escaped chars are not displayed as letters.
By the way do you mind writing the correct html and the rewrite code. I’d read something about an endless loop in the link I mentioned above. That’s why I changed it to ‘searchrd’ while testing.
I can’t see why it does not match the regex above. This is not the exact code I used but as far as I remember it worked.
You should post the snippets of exact code that you’re using. It’s hard to tell exactly what you’re trying to do. Are you sure you don’t want to just POST the data from the form?
Okay, in order to help me and others that might read this thread, would any of you write a sample code for rewriting:
search.php?q={query}
to
/search/{query}
David thanks for the flags notice.
I think this level of rewriting is over my head right now and I have other things to take care of in the project so I’m now settled with a simpler rewrite without a redirect.
Because it’s inadvisable to write “loopy” code, i.e., redirect FROM the serve-able code to a new format and then back to the serve-able code is a clear abuse of the server, let me decline. IF you are interested, I do have this covered in my tutorial along with a WARNINGNOT to do this on a production server - especially a server which is not dedicated and which you mod_rewrite code is residing in an .htaccess file.
Hmmm, other than mod_rewrite, I can only think of hijacking the Submit function with jQuery and using it to send the request in the format you’d like to see.
IF you insist on using mod_rewrite, the following SHOULD do it for you (but please report back any problems so others don’t encounter the same difficulties):
Thanks for valuable contribution to this thread. Below is my current rewrite choice (hoping it’s in good shape), but I’ll test the code you’ve provided when I have time.