4

I just moved my website to Wordpress from another service. Unfortunately, this means that although I was able to import all of my previous content to Wordpress, the post permalinks are now entirely different.

Unfortunately, I can't simply change the structure of the permalinks in Wordpress because the old permalinks from the old website contain a random number in part of the permalink, so it's impossible to reliably reproduce the link.

My only option is to create 301 redirects to each article. That's no problem because I've also used a script to record and match the old permalink to the new permalink and they are all sitting in a text file.

My question is though, will having almost 1000 redirects in the .htaccess file significantly slow performance of the page overall?

  • 1
  • @StephenOstermiller What about a Wordpress plugin like Redirection? It doesn't appear to add the redirects to the .htaccess file on my server, so is it a more optimal way to do it? – ComputerWhiz May 6 at 16:28
  • 1
    Since you have a text file with old/new links, could you import that file into database and update the database using SQL? See wordpress.stackexchange.com/questions/58625/… for tables impacted. – Trebor May 7 at 19:02
  • 1
    @Trebor Is the idea of that to change the permalink structure back to the "old" URL and eliminate the redirect altogether? (Although maybe the old permalinks weren't particularly user friendly?) – MrWhite May 7 at 21:12
  • 1
    @MrWhite, yes. If you can keep the old path by simply changing the slug/path it might save having to do any redirects. They have a text file that maps old and new. It would be relatively easy (not seeing the file) to use a SQL UPDATE command to change the slugs. Of course, without seeing the old slug/path, we don't know if there's characters that would break WP. – Trebor May 7 at 21:21
5

will having almost 1000 redirects in the .htaccess file significantly slow performance

Having 1000 separate redirect directives in .htaccess could certainly impact performance, although that may not be "significant" to the running of your site.

However, you shouldn't be implementing these type of redirects (site migration, different URL structure with no discernable pattern) in .htaccess to begin with. The .htaccess file is processed on every single request, including all requests for your static resources (CSS, JS and images etc). You could make exceptions for your static resources, however, you don't need to...

You want to prioritise normal site visitors, not the redirects for URLs that have changed. Since the old URL does not exist then the code that processes the redirects should only execute when your site determines that it would otherwise result in a 404. Depending on your site structure, you could either do this with a custom 404 ErrorDocument or with a plugin in the case of WordPress. By doing it this way, normal site visitors that request a "new" URL are not impacted in any way.

What about a Wordpress plugin like Redirection.

Yes, I believe the "Redirection" plugin is able to do this. See also the question that @Stephen linked to in comments:

  • Is it possible for .htaccess file to use a regular expression to look for the random number portion of the string and strip it out before redirecting? I'm not a htaccess person, but I know you are. Would this be practical way of reducing the number of redirects? – Trebor May 8 at 20:42
  • @Trebor That's possible, although I would think this "random number" is really the "unique ID" that identifies the old URL (as opposed to just some arbitrary random number), so would need to be present in order to identify the target URL. – MrWhite May 8 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.