CroNiX Posted January 15, 2009 Share Posted January 15, 2009 Im doing some SEO optimization for a client and need to be able to change urls like: http://www.domain.com/something/some_other/oh_blah to: http://www.domain.com/something/some-other/oh-blah Basically change all underscores (_) to dashes (-) where ever they appear. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/140993-rewrite-anything-with-underscore-to-equivalent-with-dash/ Share on other sites More sharing options...
trq Posted January 15, 2009 Share Posted January 15, 2009 You'll really want to handle this on the application side not really with mod_rewrite. For instance, say your current rule is something like.... RewriteRule ^something/(.+)/(.+)/$ index.php?module=$1&action=$2 [L] Then you could simply use (very simplified) ..... $module = str_replace('-', '_', $_GET['module']); $action = str_replace('-', '_', $_GET['action']); $obj = new $module; $obj->$action(); In your code. Quote Link to comment https://forums.phpfreaks.com/topic/140993-rewrite-anything-with-underscore-to-equivalent-with-dash/#findComment-737922 Share on other sites More sharing options...
CroNiX Posted January 15, 2009 Author Share Posted January 15, 2009 Thanks for taking the time thorpe. All of this info is stored in the database, and I will be changing the underscores to dashes there, no prob. The problem arises when someone has an old bookmark, I would like it to forward to the new one. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/140993-rewrite-anything-with-underscore-to-equivalent-with-dash/#findComment-737926 Share on other sites More sharing options...
trq Posted January 15, 2009 Share Posted January 15, 2009 Bookmarks using underscores would still work using the above method. Quote Link to comment https://forums.phpfreaks.com/topic/140993-rewrite-anything-with-underscore-to-equivalent-with-dash/#findComment-737946 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.