How to 301 redirect Joomla htaccess with multiple query parameters

I’ve recently had the opportunity to migrate a Joomla website to WordPress, and it wasn’t a common solution. Please note that this Joomla website contained ugly URLs, not SEO Friendly (SEF) URLs.

An example of an ugly URL is /index.php?option=com_content&view=article&id=91&Itemid=156.

*An ugly URL is also nicknamed as ‘URL containing Query parameters’.

How Joomla works with 301 redirects

Joomla will only allow redirects if the link/page brings up a 404. In that case, it will be simple to redirect. That way, you’ll only have to activate the plugin (not extension) ‘System Redirects’. And apply the redirects to those broken pages.

But let’s say that you want to redirect the entire website — containing working links — to another website? Let’s say that it’s WordPress.

Unfortunately you couldn’t make use of Joomla’s redirects feature. I haven’t found an extension yet that could redirect working Joomla links, but please let me know in the Comments if you do.

I’ve resorted to using the .htaccess file, but then again met another face-off:

You cannot Redirect 301 ‘working Joomla links’ in the .htaccess file.

And this is what the post will be about ^^.

Here’s the code sample to be pasted to the bottom of .htaccess file, repeat as desired (with 1 ReWriteEngine On only):

*Disclaimer: Suit the code to your own specification

Explanation of the code sample

That’s not called ‘301 redirects’ anymore.

They’re called 301 rewrite rules.

I realised that if you’ll be redirecting ugly URLs, that you have to redirect them using rewrite rules.

This worked for me, however the drawback is that it is a lengthy mundane process, especially if you have 100 URLs to redirect.

Luckily, I only had to redirect 24 URLs, and each one took me 8 seconds to duplicate and proofread. So that’s 8 x 24 = 192 seconds / 60 = 3 minutes, however surgeon focus is required.

What’s the Question mark for?

Take note of the symbol ? at the end of the Rewrite Rule.
That question mark strips out everything to the right of it.
If we don’t have this question mark (a RegEx term), then we get this:

Rewrite Rules make things look purty!

All my redirects are just going to the new website homepage!

Check that you placed your homepage redirects to the very bottom of this code snippet.
Like this:

The .htaccess file reads from bottom to up in some way, and it will override the homepage ^/$ if it finds something more specific to its condition, like if it were on the "/index.php page containing the queries option=com_content&view=article&id=34&Itemid=121".

So place the homepage redirects to the very bottom.

Wrapping Up

The following summary points are:

  • 301 redirects for Ugly URLs must be through 301 Rewrite Rules
  • ‘301 redirects’ are not equal to ‘301 Rewrite Rules’
  • Place homepage rewrite rules to the very bottom of the snippet
  • Joomla only redirects broken URLs through its system plugin

Please let me know in the comments below if there are any improvements to this article. I am very open to feedback and since I am not a Joomla Guru I would love to your hear feedback on this.