I have a site that had used underscores instead of a dash in its mysql database. I have changed the database so all underscores are now a dash. Google has about 5,000 pages indexed (using the underscore) and I would like to do a 301 redirect if it is possible. Right now they just get a custom "request not found page". All pages are dynamically created in php and urls are processed using mod_rewrite. Is there anything like str_replace which would look for any underscore and change it to a dash? If not, what about a list of exact "keywords" i.e. "united_states" "purple_widgets" that could be changed to "united-states" "purple-widgets"? As all URI's go through mod_rewrite, is there any problem with making all URI requests (even correct new url's with a dash) a 301?
Ok this is not a difficult thing to do with mod_rewrite mjewel, so you are in luck! I would suggest attacking the google index problem in 3 ways... Using mod_rewrite to send a 301 redirect to the page where all _ are converted to -. Using your sites robots.txt file to tell google not to index any pages with an underscore (_) in it. Using Googles webmaster tools to verify your new robots.txt file is working and to speed up googles re-indexing. 1. mod_rewrite (based on code from "Rewrite urls separated by _ underscores to - dashes") Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteRule !\.(html|php)$ - [S=5] RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6-$7 [E=underscores:Yes] RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6 [E=underscores:Yes] RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=underscores:Yes] RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=underscores:Yes] RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=underscores:Yes] RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=underscores:Yes] RewriteCond %{ENV:underscores} ^Yes$ RewriteRule (.*) http://domain.com/$1 [R=301,L] Code (markup): 2. robots.txt (based on code from "SEO with Robots.txt") User-agent: Googlebot # disallow the indexing of files with an underscore _ anywhere in url Disallow: /*_* Code (markup):