? Failure

User tests: Successful: Unsuccessful:

avatar jo-sf
jo-sf
9 Sep 2014

Suppose you have a web server using Joomla where this web server is both reachable via http://www.example.org/ and http:/example.org/. With the current implementation of the redirection plugin you need to define two redirections within the redirect manager component for every page you want to automatically redirect from its old location to its new location:

old page: http://www.example.org/path/to/old/page.html
=> new page: http://www.example.org/path/to/new/page.html

old page: http://example.org/path/to/old/page.html
=> new page: http://example.org/path/to/new/page.html

With my proposed file change it would be sufficient to define only one redirection in this case:

old server-relative page: /path/to/old/page.html
=> new server-relative page: /path/to/new/page.html

avatar jo-sf jo-sf - open - 9 Sep 2014
avatar jissues-bot jissues-bot - change - 9 Sep 2014
Labels Added: ?
avatar jo-sf
jo-sf - comment - 9 Sep 2014

Sorry but what do mean with "here we need to remove the tabs"? The lines 68 through 72 are not part of my patch but were instead the original staging code, and I simply copied this code into the lines 80 through 84, indented it with an additional tab and changed "$current" into "$currRel".

I would even argue that the statement starting with "$query =" and being continued over the next 4 lines is better readable if the continuation lines are indented with one additional tab.

avatar mbabker
mbabker - comment - 9 Sep 2014

The tabs are fine for chained method calls.

avatar zero-24
zero-24 - comment - 9 Sep 2014

thanks @jo-sf

but atm i can't get it work.

what i try

  • apply your patch
  • enable redirect plugin
  • go to http://localhost/cm45/index.php/park-blog/17-first-blog-post.html
  • all ok
  • disable the First blog post artikle on the Backend
  • 404 error --> ok
  • see the URL catch the URL in com_redirect
  • Configuration:
    • First
      • Source URL: http://localhost/cm45/index.php/park-blog/17-first-blog-post.html
      • Destination URL: /cm45/index.php/park-blog/18-second-blog-post.html
    • Second
      • Source URL: /cm45/index.php/park-blog/17-first-blog-post.html
      • Destination URL: /cm45/index.php/park-blog/18-second-blog-post.html

But never we jump into your if as $link contain every time a value.

But also if i force it to use it (place a $link = NULL bevor the if statment) it don't work well.

Or i miss somthing/do things wrong?

avatar zero-24
zero-24 - comment - 9 Sep 2014

@jo-sf

i have just test it without your patch and it works. My Browser was it. Without the patch it don't work

  • Configuration
    • Source URL: /cm45/index.php/park-blog/17-first-blog-post.html
    • Destination URL: /cm45/index.php/park-blog/18-second-blog-post.html
avatar jo-sf
jo-sf - comment - 9 Sep 2014

about the tabs at line 75: I removed them a minute ago (they came from editing the file in the github web interface: if you open a new line below an indented line this new line is automatically filled with as much tabs as has the previous line, and these tabs are not removed even if you leave the line apparently empty it still contains the tabs automatically placed there).

about your failed test: I have to investigate and then I'll come back and leave a comment here.

avatar jo-sf
jo-sf - comment - 9 Sep 2014

zero-24, are you complete sure that the complete redirection path (http://localhost/cm45/...) is no longer registered in the redirect plugin and that your browser isn't fooling you? If you've tried it before within the same browser session (and maybe even after restarting the browser - depends upon the way your browser caches redirects it received before) your browser probably didn't send the URL to the server but took the redirection information from its cache.

According to the source code in redirect.php this plugin by default searches only for the complete URL including scheme, host, port, path, query and fragment, and only if it finds this complete URL in the database table '#__redirect_links' it will use the new URL found there (currently there is no restriction upon the new URL, it might be a full URL or a server-relative URL).

A query with the where clause

old_url = 'http://localhost/cm45/index.php/park-blog/17-first-blog-post.html'

should never find an entry in the '#__redirect_links' table where the field 'old_url' contains only

/cm45/index.php/park-blog/17-first-blog-post.html

(at least I would expect that the database is not so smart to match these two strings).

avatar zero-24
zero-24 - comment - 9 Sep 2014

zero-24, are you complete sure that the complete redirection path (http://localhost/cm45/...) is no longer registered in the redirect plugin and that your browser isn't fooling you?

Woops my browser was it. I have now try it with Chrome and Opera instead of FireFox and it don't work.

So my setup is the following:

  • The First blog post is disabled.
  • Configuration
    • Source URL: /cm45/index.php/park-blog/17-first-blog-post.html
    • Destination URL: /cm45/index.php/park-blog/18-second-blog-post.html

Without your patch

  • 404 error

With your patch

  • i still get a 404 error.

I think the issue is located here

if (!$link)
[...]

We never get in this if as this condition don't work, it works if we add a line like $link = NULL; bevor the if statement.

avatar jo-sf
jo-sf - comment - 9 Sep 2014

Well then what is the result of

$link = $db->loadObject();

if the query set up in lines 68ff. returns no results at all?

I looked at the 'if' statement in line 90 (line 77 without my patch)

if ($link and ($link->published == 1))

and assumed that '$db->loadObject()' returns NULL if there is no match in the database. At least I would understand the documentation in

libraries/joomla/database/driver.php

in line 1225ff. in this way.

Is there anything I'm missing here?

avatar zero-24
zero-24 - comment - 9 Sep 2014

@jo-sf

yes it looks strange. Anyhow $link contains 1 (using print_r($link);)

Please test this here:

if (!$link->new_url)
{
[...]

It work for me (is clear if we have no redirect) and is the relevant part that we need to redirect

avatar jo-sf
jo-sf - comment - 9 Sep 2014

@zero-24

I think I finally found what's the problem here: the search might also find a redirect entry which is either not published or even in the trash - but a match is a match, and $link points to an object.

Due to that I changed my code from

if (!$link)

into

if (!$link or ($link->published != 1))

which works well for me even if there is an unpublished redirect or even a trashed redirect in the database and a valid redirect Joomla shall use. The only disadvantage is that for every invalid URL the plugin first checks whether there is an entry in the database with the complete URL, and if there is no such published entry it repeats the search with the server-relative URL.

Can you please test whether this change works for you as well?

avatar zero-24
zero-24 - comment - 9 Sep 2014

thanks @jo-sf it works now good here.

This comment was created with the J!Tracker Application at http://issues.joomla.org/.

avatar zero-24 zero-24 - change - 9 Sep 2014
Category Front End Plugins SEF
avatar zero-24 zero-24 - change - 9 Sep 2014
Easy No Yes
avatar zero-24 zero-24 - change - 9 Sep 2014
Category Front End Plugins SEF Front End Plugins
avatar b2z
b2z - comment - 17 Sep 2014

@test all good! Good job.

This comment was created with the J!Tracker Application at http://issues.joomla.org/.

avatar zero-24 zero-24 - change - 17 Sep 2014
Status Pending Ready to Commit
avatar zero-24
zero-24 - comment - 17 Sep 2014

thanks @b2z moving to RTC

This comment was created with the J!Tracker Application at http://issues.joomla.org/.

avatar phproberto phproberto - change - 8 Oct 2014
Labels Added: ?
avatar phproberto phproberto - close - 10 Oct 2014
avatar phproberto phproberto - change - 10 Oct 2014
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2014-10-10 12:17:27
avatar zero-24 zero-24 - change - 14 Oct 2015
Labels Removed: ?

Add a Comment

Login with GitHub to post a comment