Jump to content

Rewrite anything with underscore to equivalent with dash


CroNiX

Recommended Posts

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 :)

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.

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.