Support

Admin Tools

#41527 Bulk Import 301 Redirects Joomla 4 Admin Tools

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
4.4.0
PHP version
8.2
Admin Tools version
n/a

Latest post by nicholas on Wednesday, 29 January 2025 02:19 CST

trevor

Hello,

I have over 400 301 redirects that need to be added to the site for a migration. I have used joomla 4 sites without admin tools and I usually can just place them in the htaccess file. However i tried it and it doesnt work. i have also tried putting it in the "Custom .htaccess rules at the bottom of the file" with no luck. I understand there is a feature to add them, however I have all the urls structured in a text file. I cant add over 400 individually. Is there a way to copy and paste all the formatted redirects into the htaccess file?

This is what I added. the urls are correct because i tried with the individual one and it worked.

##### RewriteEngine enabled - BEGIN
RewriteEngine On
##### RewriteEngine enabled - END

##### Custom 301 Redirects - BEGIN
RewriteRule ^/laser-beam-delivery.html $https://www.haaslti.com/products/beam-delivery [R=301,L]
##### Custom 301 Redirects - END

# PHP FastCGI fix for HTTP Authorization
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
##### RewriteBase set - BEGIN
RewriteBase /
##### RewriteBase set - END

nicholas
Akeeba Staff
Manager

First, a warning. Adding redirections to the .htaccess file is a bad idea when you have more than a couple dozen. The reason is that the .htaccess file needs to be loaded and parsed for every single request, including PHP (Joomla, WordPress, …), CSS files, JavaScript files, images, videos, everything. When you approach 300 redirections even the fastest server will start showing a measurable page rendering delay which will have an adverse impact on your search engine rankings.

We strongly recommend that you use Admin Tools' URL Redirec feature instead. This only runs when Joomla is generating a page (typically, an HTML page), and they're typically much faster than parsing a .htaccess file.

Regarding the custom redirections, if you have them as RewriteRule files you can add them to the "Custom .htaccess rules at the top of the file" since you want them to take effect before any of the protection rules.

Another reason they might not work, is that the sample you provided is wrong. If they are all in this format, well, your site will break. Let's take a look:

RewriteRule ^/laser-beam-delivery.html $https://www.haaslti.com/products/beam-delivery [R=301,L]

The space should be after the $, not before it. The structure you are trying to do is RewriteRule MatchRegex RedirectURL [FLAGS]. When the URL path matches the regular expression MatchRegex Apache will redirect the user's browser to RedirectURL. The FLAGS you are using tell Apache to perform the redirect using the HTTP 301 status code (Moved Permanently), and stop processing other rules when this rule matches; the flags are correct.

The problem is your MatchRegex. The ^ matches “start of string” and the $ matches “end of string”. That's why you were trying to write ^/laser-beam-delivery.html$ without a space before the $ character. Further to that, this being a regular expression the dot (.) has a special meaning: match any character. This rule is therefore also wrong because it would match laser-beam-delivery-html which is not what you want. Instead, you need to “escape” the dot using \. in its place.

The correct rule would be:

RewriteRule ^/laser-beam-delivery\.html$ https://www.haaslti.com/products/beam-delivery [R=301,L]

This means that you need to go through all your rules and check them one by one. If you are going into this trouble, why not transfer them into Admin Tools' URL Redirect feature? In any case, it's up to you. I have to give you both options, explain the pros and cons, and let you decide what works best for your use case.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

trevor

Hi Nicholas,

Thankyou for the in depth answer, I really appreciate it.

I'm fine using the Admin tools redirect feature. However the reason I didn't initially was because it seems that I have to enter them one by one. They are all formatted in an excel table with column 1 being the old URL and column 2 being the new url. That way I can quickly restructure all redirect commands with some simple excel string operations. Is there a way to bulk import these some how? Doesn't really matter the format since they are in an excel table, I can format them however. 

How do you recommend going about adding al the redirects?

Thanks for your help,

Trevor

nicholas
Akeeba Staff
Manager

You can do the same thing I did: work them on a spreadsheet, import them in the database.

Create a spreadsheet with two columns, labelled (at A1 and B1 respectively) source and dest.

The source column contains what you put in “Visiting This”, for example: /redirect-me.

The dest column contains what you put in “Takes you here”, for example: https://www.example.net/i-have-been-redirected-to-this-page.

Export the spreadsheet as a CSV file.

Now you can go to phpMyAdmin in your hosting control panel and import the CSV file into the #__admintools_redirects table.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

trevor

Ahhh I didn't realize you can do that. That's exactly what I was looking for...

As far as formatting each of those columns, is there any documentation or is it just as simple as you mentioned.

 

For my original example:

source: /laser-beam-delivery.html

dest: https://www.haaslti.com/products/beam-delivery

 

Do i have to specify the redirect type?

 

Thanks for the suggestion

 

nicholas
Akeeba Staff
Manager

The source column must have the leading slash and any trailing extension (if that was present in the original URL). For example:

  • https://www.example.com/foo becomes /foo
  • https://www.example.com/foo/bar.html becomes /foo/bar.html

The dest column can be one of two things.

  • A relative URL, without the leading slash. For example, https://www.example.com/somewhere-else becomes somewhere-else.
  • A full URL, e.g. https://www.example.NET/something.html.

If you absolutely want to keep the order of the redirections you are entering, add a third order column which increases monotonically i.e. 1, 2, 3, 4,…

You don't have to specify anything else. The default redirection type is exact match. That's what you would end up doing with the spreadsheet, that's why I am not discussing the other columns at all.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

trevor

Hi Nicholas,

 

I was not able to get the import to work. So i tried manually adding a single redirect in the admin panel and looked at the myphpadmin table to see the structure. While the structure you provided was close, it looks like its actually slightly different. 

source: Where you want the link to take you including the full url

dest: the old redirected relative url

This structure works. It successfully redirected me to the correct page.

Your structure make more sense to me, however this is how it was configured when I manually added it in admin tools joomla backend. Please see the images below for reference. Let me know if this checks out. Maybe I understood your messages wrong. Not sure

trevor

Okay after messing around a bit this is the final csv structure that works correctly. Its backwards from my intuition. dest is the old url, source is the new url for the new site.

trevor

Sorry the text got cut off in the last picture, here is the final working version

- the csv structure

- the myphpadmin table structure

- the admin tools url redirect feature structure.

 

Posting this for people of the future having a hard time with this

System Task
system
The ticket information has been edited by Trevor Haas (trevor).

nicholas
Akeeba Staff
Manager

Yeah, I misread the two columns. There's a reason we have changed the UI labels to "When you visit this" and "you go here".

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!