How would I rewrite this url? www.games.com/best games.php to www.games.com/best_games.php say I want to change the " " to "_" Thanks.
Here a rewrite rule that should work, assuming Rewrite Engine is on, for apache - very strict - just for this page: Rewrite Rule ^best\ games.php best_games.php You just need to escape the space character if you want to use this elsewhere. I'm assuming the problem was that the space is the special character that separates the parts of the rules. This should fix that. , Mike
Thanks for the Help Mike Rep added , Now say I wanted to take this to the next level and rewrite a character each time it showed up in a URL. For example: " " -> "_" "é" -> "e" "ç" -> "c" Instead of the above example when it was just one URL, being able to implement these changes on the fly for multiple URLs if any of the characters showed up. Thanks
Hey again, thanks! If you need to just replace one character multiple times for multiple ULR's, try (I'll use "H" -> "h" since I can't seem to figure out how to write the fancy characters you want replaced The concept is the same. In this rule you have to use the third (optional) part of the RewriteRule, so you can set some options to apply to your sub's. Line 1: RewriteRule ^/(.*)H(.*)$ /$1h$2 [N,E=redir:yes] Line 2: RewriteCond %{ENV:redir} ^yes$ Line 1: Substitute h for H as many times as you need to in the URL. Don't send any redirect requests back to the browser, but set the redirect flag. You can add multiple lines like this for different substitutions before you add Line 2, which might be line 15 - who knows? Line 2: Check and see if the redirect flag is set. If you did one, or any number of substitutions in Line 1, then it is and you'll send the redirect to the user's browser. You can take out the N in the third section of the RewriteRule if you don't want to do an internal rewrite and just do a redirect (If you remove the end you don't need the whole section with E=redir:yes and the RewriteCond line. Basically, if you want you can duplicat the first rewrite rule as many times, for as many characters, as you need and then do the RewriteCond The way this is set up, you'll be doing all the character replacements and redirecting internally (N in final part of rule) while setting the redirect flag (E=redir=yes) and then doing one redirect once all the substitutions are done. Otherwise you'll redirect the URL once for every instance of the substitution, which could result in tons of traffic between your server and the user browser. Probably not noticable, but maybe confusing in your logs Sorry to be so wordy; probably needs less explanation than I gave, but I got started... , Mike (Lots of smileys removed because I got an error when trying to post this to you (smile))