[imp] Allow setting of Http status code in com_redirect#4292
[imp] Allow setting of Http status code in com_redirect#4292wilsonge wants to merge 10 commits intojoomla:stagingfrom
Conversation
|
I know it needs postgres and sql server changes to be made but I'll do that when this is all good and ready to go so if we change things around on review I have to change 2 files not 6 :P |
|
Any test cases? ;) |
e4f7381 to
90674e5
Compare
libraries/joomla/application/web.php
Outdated
There was a problem hiding this comment.
@wilsonge I think you mean @deprecated 4.0 here?
94d3b2c to
1d82cea
Compare
|
Could you add _LABEL when it fits? |
|
@test: The redirect works when setup. One thing I miss though is that the Apache log doesn't show the redirect. It only shows the 200 status for the target URL. I am not sure if that is an Apache setup issue or an issue with this code. From what I could find is that Apache logs 301 redirects out of the box.
I cannot reproduce that, the page is still redirected to the destination URL. Like the 301 also a 500 error is not logged in the Apache log. The selector is too small, make it wider for better readability. |
|
Fixed the lang strings JM |
|
@test: The redirect works as expected, it was a case of aggresive browser caching by FireFox. Picking another test URL and it works. Only remaining issue is the width of the dropdown. |
|
Thanks so much for the feedback Roland! Fixed the width of the select elements as requested :) |
|
Having some issues with testing this patch on the latest development build 3.3.7-dev, when I try to force a 404 in order to redirect (rather than manually creating it from scratch) I'm unable to save it to the database. The error message received: Furthermore, the destination URL appears to be mandatory wheras it does not have an asterisk next to the label which, in my view as a user, would suggest that it was not a required field. Indeed with some error codes such as 410 (Gone) there is no need to redirect anywhere - it should just provide that error code as the page no longer exists. |
|
@RCheesley To be able to save the change to the database you will need to manually execute the SQL file. |
|
@test successful with correct code being output in live headers, I have suggestions/comments for improvements
|
|
Updated description to add about the database change. Apologies for not making that clear. The destination URL should not be mandatory in advanced mode will investigate that as that is a bug. The location of the field is deliberate. Whilst there is only this 1 advanced field at the moment, the code has been written in such a way that infinitely more can be added by just adding them to the XML file. With that in mind it made sense for any of the admin fields to be added at the end at the current list. The other option was to create a new tab - but that made little sense for what is currently one field. |
|
Thanks for the spot! They were written - just missed them out of the commit! |
|
👍 The dates / names of the file gets |
|
I would assume so too. The date is when I wrote the initial mysql file. I just kept the name consistent |
|
Too late to get this in 3.4 instead of staging? |
|
We are not going to have more 3.3.x series so I think it's ok 🍶 |
Famous last words? 😄 |
|
Then you guys get my awesome new feature early 😆 |
I've found a B/C issue in 3.4.0-alpha related to a change done in /libraries/joomla/application/web.php, line 549 joomla#4292 If a third-party extension uses the deprecated $app->redirect($url, $msg), as $msg is not numeric, it will return a error <b>0 You have not supplied a valid HTTP 1.1 status code</b>
|
Hi! I've found a B/C issue in 3.4.0-alpha related to a change done in /libraries/joomla/application/web.php, line 549 if (!is_int($status) && !isset($this->responseMap[$status]))
{
throw new \InvalidArgumentException('You have not supplied a valid HTTP 1.1 status code');
}
If a third-party extension is still using $app->redirect($url, $msg) as $msg is not numeric, it will return a error 0 You have not supplied a valid HTTP 1.1 status code PR with patch: #5247 @wilsonge could you confirm this is fixing the issue ? |
|
Sorry @wilsonge to have disturbed you, i have close the PR because the issue was not in joomla core, but in a bad practice i've done a long time ago in one of my file, which one was working before 3.4.0-alpha... (in all cases, Thank you for your PR, because i was able to found a very crap code and to fix it in my own code! ) ;-) |
|
Don't worry man. Glad you got it sorted :) |
|
Warning! |
|
My suggestion is to fix the main B/C that I'm seeing with the old B/C API of Joomla 2.5 where second argument of redirect() is a string, and third too: I commented here that the new statement at this line: Suggesting that instead of Agree ? |
|
@wilsonge To reproduce the B/C bug and test the proposed simple fix, just install Community Builder from web-installer, publish CB login module, and try logging in or logging out using it in frontend. |
|
what when we used boolean for the 303/301 redirect? |
|
@infograf768 https://github.com/joomla/joomla-cms/blob/staging/tests/unit/suites/libraries/cms/application/JApplicationCmsTest.php#L524 this unit test demonstrates your code should work perfectly still with a 301 redirect. If it is broken then it is not related to the changes I made. @beat Thanks for code sample. I'll get a PR to fix stuff within the next couple of hours with unit tests |
|
Beat your issue should be fixed by #5290 If we don't have a valid status code I added in your suggested check and just defaulted to 303 to keep b/c for now. However I think for 4.0 (when b/c can be broken) we still should revert to an invalid argument exception to keep things clean I'd still advise you move to the non-2.5 way of doing things. Does passing in an empty message not just seem horrifically wrong xD |
|
@wilsonge Thanks! PR #5290 works for me too code-wise. Will test and feedback on the 5290 PR. In Joomla 4.0, the whole B/C "if" part could be removed (which would have been another advantage of fixing the B/C issue in.... the B/C aera lol) As said above, have added a task to modernize that part of old code :) But I was worrying about existing sites and existing extensions (for 2 feedbacks here testing off master, probably 200+ would have broken too). Btw, a redirect without a message to display on top is perfectly legit and ok imho in many situations where the hassle of a confirmation message for an obvious change of state is a UX overkill. |
|
i just wonder if @infograf768 has still language issue ? |
|
Looks like I now get a 301 instead of the unwanted 303. Merging. Thanks. |
Fix minor b/c break in #4292

This feature allows the setting of the Http status code in com_redirect. This has many SEO related benefits as you may well wish to redirect with a non-301 code (a 501 or something crazy like that even).
It also gives much greater flexability to the redirect method in JApplication in order to do this. As that only allowed a redirect with a 301 or 303.
As this is an advanced option and should only be used by those who actually know what their doing I've dumped it in an advanced options parameter for the component. I've also built it in such a way that we can add more things into the advanced section in the future if we want. If the user has this turned off (which he will by default) then they will continue to redirect with a 301
Testing Instructions
Apply the patch and also apply the database change found at https://github.com/wilsonge/joomla-cms/blob/redirect-upgrade/administrator/components/com_admin/sql/updates/mysql/3.4.0-2014-09-16.sql
Go into the backend and navigate to com_redirect (make sure you have the relevant plugin enabled).
Check that the component still works exactly the same as currently - we don't want to scare anyone off with new options :P
Now we'll test the new feature - go into component options and enable the advanced mode (under advanced options tab). In the edit form for a given link this will give you the extra option to set a HTTP redirect number - this is any valid HTTP code. If you set a 3xx code then we redirect as usual. If you choose a non-3xx code then it will display the generic error page in Joomla with the selected error code.