htaccess rewrite incoming links to new one

I’m having a problem with site migration and old links. Now, its not just a server migration, it was also a CMS migration. Site went from umbraco (asp.net) to wordpress. Problem is that google indexed old URLs. We have a way to rework links to make them work. I’ve been using this method to rework links and used WP plugin for redirect. The problem is there is way to many links for this plugin.

I was wondering is there any way to rework links dynamically with htaccess.
So, here is how links should be rewritten:

Read More
http://example.com/something/XXXXX-some-text.html
-->
http://example.com/something/some-text-XXXXX
where XXXXX is some number between 100 and 100,000

This method works, only problem is that there is more then 60,000 links…

Any suggestions?

P.S.
There are also some other links that should be skipped, cause we don’t have a way to rework them…

Related posts

1 comment

  1. Is this what your want?

    RewriteEngine on
    RewriteBase /
    RewriteRule ([a-zA-Z-]+)/([0-9]+)-([a-zA-Z0-9-]+).html /$1/$3-$2 [L,R=301]
    

    Put this at the top of your .htaccess file in WordPress installation.

    • ( ): will capture a string
    • $#: will print the captured string in the redirection
      • $1: will print the first captured string
      • $2: will print the second one
      • $3: will print the third one

    You can use this tool to test that kind of simple rules.

Comments are closed.