2

I'm having a hard time redirecting URLs on multilingual Joomla site.

New site has following URL structure: http://sitename.com/[language]/[pagename].html and old site URL structure is as follows : http://sitename.com/[pagename]?lang=[language].

I have tried several regex incantations but none of them work. It seems like Joomla multilingual rewrites are overriding them somehow.

Here's one of the regexes I've used, I have tried with redirect as well:

RewriteRule /(.+)\?lang=(.+) /$2/$1.html [L,R=301]

It just doesn't work no matter how I put it and I want to redirect old URLs to new ones.

1

First of all, I'm by no means a .htaccess guru, but here's an idea that might work:

RewriteCond %{QUERY_STRING} .*lang=en.*
RewriteRule ^(.*)$ /en/$1.html? [R=301,L]

RewriteCond %{QUERY_STRING} .*lang=es.*
RewriteRule ^(.*)$ /es/$1.html? [R=301,L]

RewriteCond %{QUERY_STRING} .*lang=no.*
RewriteRule ^(.*)$ /no/$1.html? [R=301,L]

You'll have to repeat the two lines for each language you want to redirect, but it shouldn't be difficult unless you have a crazy amount of languages.

The first rule checks if lang=en is present in the URL, and if it is, the URL is rewritten using /en/ in the path. The ? in html? removes any URL parameter. The L parameter forces the rule to be the last one, and any rule below is ignored.

You can test this (and other solutions) using the htaccess tester.

Hope it helps, at least it's worth a try.

  • Yes, I ended up doing something similar with ReDJ component in the end. – Reygoch Nov 13 '14 at 21:51
1

You might want to try a tool called Mod Rewrite Generator (http://www.generateit.net/mod-rewrite/index.php).

It's a tool that allows you to insert any URL with parameters (domain.com/index.php?lang=en), then choose how you want to use them in the final url, and then gives you the code for your .htaccess file.

I find it usefull in many situations.

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.