Forum Moderators: phranque
Welcome to WebmasterWorld [webmasterworld.com]!
I'm not sure whether you are asking for a specific solution for rewriting "Astin%20Martin" to "Astin_Martin", or for a more general case of rewriting "<anything>%20<anything>" to "<anything>_<anything>", but this thread [webmasterworld.com] discusses several methods for replacing certain characters with others for the general case. It may serve to give you an idea of how to solve your problem.
Jim
RewriteRule ^Astin\ Martin\.html page.php?m=Astin_Martin [L]
RewriteRule ^([^/]+)\.html page.php?m=$1 [L]
RewriteRule ^([^\ ])\ ([^\ ])$ $1_$2
RewriteRule ^([^/]+)\.html page.php?m=$1 [L]
Jim
but
the var that I must send is with space
I need make the inverse operation
I have a link :
page.php?m=Aston Martin
I must, with mod_rewrite, to transform in
Aston_Martin.html
_________
In your code the page called Aston Martin.html is
transform to Aston_Martin.html, and value var is Aston_Martin
_________
I needed that Aston_Martin.html called a page with value var Aston Martin
Thks :))
I don't think it's possible to output a space from mod_rewrite. The best you can do is to output a hex-code-escaped space (%20).
A better alternative would be to change your PHP script to recognize a different character (other than a space).
RewriteRule ^Astin_Martin\.html$ page.php?m=Astin\%20Martin [NE,L]
RewriteRule ^(.+)\.html$ page.php?m=$1 [L]
RewriteRule ^([^_]+)_(.*)$ $1\%20$2 [NE]
RewriteRule ^(.+)\.html$ page.php?m=$1 [NE,L]
Note also that literal periods "." in regular expressions patterns must be escaped by preceding them with a backslash "\", for example, "file\.html".
Jim
but this return error 404
RewriteRule ^([^_]+)_(.*)$ $1\%20$2 [NE]
RewriteRule ^([^_]+)_(.*)$ /page.php?m=$1\%20$2 [NE]
Is it possible that the name of your php page actually contains an underscore "_" character? In that case, the Rule would apply to your php page as well, and you might get a loop if any process makes another subrequest.
The solution (if this is the case) would be to add a condition to the rewrite:
RewriteCond %{REQUEST_URI} !^/script_page\.php$
RewriteRule ^([^_]+)_(.*)$ /script_page.php?m=$1\%20$2 [NE,L]
Jim
<edit> Corrected missing space problem </edit>
[edited by: jdMorgan at 6:14 pm (utc) on Dec. 1, 2003]
Something like this:
$newM = str_replace("_", " ", "$m");
Then call $newM in your database query, of course if you're not doing a query then this post is of no value :)