contao / news-bundle

[READ-ONLY] Contao News Bundle
GNU Lesser General Public License v3.0
9 stars 14 forks source link

The alias-url of news with external target doesn't redirect #33

Closed ADoebeling closed 6 years ago

ADoebeling commented 6 years ago

If you create a news-record with an external redirect, the newslist is linking the entry to the external ressource.

The previously generated alias-url of the news-entry doesn't redirect you. The old url is still available and shows a 1 to the screen:

image

AFAIK this is a bug as the page-module is handeling this case correctly.

fritzmg commented 6 years ago

I agree. If source of the news entry is not default, its URL should respond with a 301 status code redirecting to the configured location. I see this more as a feature than a bug fix though.

    if (null === $objArticle)
    {
        throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
    }

+   if ('default' !== $objArticle->source && substr($objArticle->url, 0, 7) !== 'mailto:')
+   {
+       throw new RedirectResponseException($this->generateNewsUrl($objArticle), 301);
+   }

    $arrArticle = $this->parseArticle($objArticle);
    $this->Template->articles = $arrArticle;

// edit: may be a 302 code is more suitable though

leofeyer commented 6 years ago

What about mailto: links? The problem still exists for them.

fritzmg commented 6 years ago

May be respond with a 404 in this case?

leofeyer commented 6 years ago

That's a very good idea. We should even do this if the external URL is not a mailto: link, shouldn't we? Because an external news or event does no longer have an internal URL.

fritzmg commented 6 years ago

Hm, so you mean responding with a 404 in general, if $objArticle->source !== 'default'? You are right, may be that is the more correct solution anyway. A 301 redirect for a URL that points to a news article which has an external link would not be correct in the sense of: the page/content did not actually "move permanently" to the new URL. It is simply an invalid URL.

leofeyer commented 6 years ago

Changed in ce44f810acef008016028643ad20aaaf0c2adb56.