Support

Admin Tools

#25368 301 redirect in admintools "url redirect"

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
n/a
PHP version
n/a
Admin Tools version
n/a

Latest post by sonosergio on Monday, 13 June 2016 01:54 CDT

sonosergio
 i think that is important have a 301 redirect instead 303
i modify the code in /httpdocs/plugins/system/admintools/feature/urlredir.php at row 170 and add

$this->app->redirect($targetURL, 301, 'message', true);
instead of
$this->app->redirect($targetURL, '', 'message', true);

i think that the type of redirect should be an option for each entry
Existing URL
New URL
Type of redirect 301/303/307
....

nicholas
Akeeba Staff
Manager
Since we have to support Joomla versions from 3.0 to 3.5 we can't have an HTTP code selection box as this feature would be inconsistent. In the future we may add such a feature or change the HTTP code.

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!

nicholas
Akeeba Staff
Manager
Actually, looking at the code again, your solution is WRONG. The problem comes from the two different generations of Joomla core code (3.0 to 3.3 and 3.4 to 3.6).

In the first generation where JApplicationSite extends JApplication the method's signature is
public function redirect($url, $msg = '', $msgType = 'message', $moved = false)


In the second generation where JApplicationSite extends JApplicationCms the method's signature is
public function redirect($url, $status = 303)

However, as you can read in libraries/cms/application/cms.php lines 974 to 1014 you can still use the four arguments call. In this case Joomla! will translate your arguments to the new style and then call parent::redirect(). In its turn, parent::redirect() is actually a call to JApplicationWeb::redirect(). However, as we can see in JApplicationCms line 1012 Joomla has a bug and does NOT translate the $moved boolean to an HTTP code integer. So, basically, you are reporting a Joomla! bug.

So despite us using the Joomla API per its documentation (docblocks), a bug in Joomla itself prevents the code from working properly. Since we have to support older versions of Joomla which do not support the new, two argument call to redirect() you'll have to live with it until we drop support for old Joomla versions – in the next version of Admin Tools, scheduled for late June to mid July.

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!

sonosergio
ok, as I understand it ...
in my case (Joomla 3.5.1) my code works
in Joomla 3.3 and older version my code not work.
In next version of Admin Tools ( mid July) you will settle the problem
Thank you!

nicholas
Akeeba Staff
Manager
It shouldn't work in Joomla! 3.5.1. Not unless you change that line to $this->app->redirect($targetURL, 303);

So, basically, the TESTED change you have to make is to replace that line with this:

			if (class_exists('JApplicationCms') && class_exists('JApplicationWeb')
				&& ($this->app instanceof JApplicationCms)
				&& ($this->app instanceof JApplicationWeb))
			{
				$this->app->redirect($targetURL, 303);

				return;
			}

			$this->app->redirect($targetURL, '', 'message', true);

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!

sonosergio
my code works
http://www.sfweb.it/13-soluzioni-avanzate.html redirect to http://www.sfweb.it/soluzioni-avanzate.html
but your code is more secure.
thank x2 ;)

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!