.htaccess rewrite underscores to hypens, strip extension, & remove trailing underscores

I'm converting my blog from movable type to wordpress.There are several thousand entries, and thankfully I am able to keep (almost) the same permalinks.

I know that with some clever .htaccess wizardry, I should be able to redirect my URLs, but I can't for the life of me figure out what the statement(s) should be.I have over 20,000 entries, so redirects on individual pages is not ideal.

Here's what I need to do:

I have a bunch of URLs like this:


I need to :

if(extension is .php) { 1. Convert underscores to hypens in the filename. 2. Remove the file extension. 3. Remove trailing hypens. }

The above would end up as such:


Anyone done something similar to this? I could really use the help on this one!


How about something like this, in the htaccess file in your document root:

RewriteEngine On RewriteRule ^(.+)_(.+)\.php /$1-$2.php [L,R=301] RewriteRule ^(.+)_\.php /$1.php [L,R=301] RewriteRule ^(.+)\.php /$1 [L,R=301]


  • Jekyll plugin to handle categories doesn't work on GitHub
  • Breakpoint Debug proper usage iOS?
  • Authorize with Permissions
  • Can't figure out what's causing my tests to fail
  • How can I detect if a URL is redirected to another one?
  • RewriteCond and RewriteRule in .htaccess
  • Dropping support for JRE 1.3
  • Why dsofile.dll still need Office Installation?
  • request follow redirection without post data
  • HTMLcollection 0 list length, [n] returns undefined, converting to an array returns an empty array
  • Theme in user control
  • How can I do a 301 redirect from http to https in Wildfly 8.2?
  • Check for stdout or stderr
  • Django how to modify database records by template
  • How do I control the soft menu button in Honeycomb?
  • Working example of paypal Website Payments Pro Hosted Solution Iframe?
  • Hudson dependencies
  • Can I put a + sign in a folder with IIS?
  • How to run requests.get asynchronously in Python 3 using asyncio?
  • System call time out?
  • Open hyperlink on click on an ggplot/plotly chart
  • Symfony2 redirect to https route fails (uses wrong port)
  • Angular page doesn't refresh after data is added or removed
  • cell spacing in div table
  • XSLT foreach repeating nodes to flat
  • How to create a 2D image by rotating 1D vector of numbers around its center element?
  • How to 'create temp table as select' in Slick?
  • pip in virtualenv gets ConnectTimeoutError
  • Thread 1: EXC_BAD_ACCESS (code =1 address = 0x0)
  • Looking for good analogy/examples for monitor verses semaphore
  • Do I need to seed any random number generator before using EVP_PKEY_keygen of OpenSSL?
  • JqueryMobile Popup menu is not working
  • Element.tagName for python not working
  • MySQL Order by column = x, column asc?
  • How to match http request and response using Jersey ContainerRequestFilter and ContainerResponseFilt
  • Repeat a vertical line on every page in Report Builder / SSRS
  • JavaScriptCore crash on iOS9
  • Weird JavaScript statement, what does it mean?
  • How do I rollback to a specific git commit
  • need help with bizarre java.net.HttpURLConnection behavior