Skip to main content

Administer redirects to internal or external URLs using Link like content

Project description

Administer redirects to internal or external URLs using Link like content. Where Products.redirectiontool or plone.app.redirector only deal with redirecting to internal URLs internal to the portal, collective.redirect allows for redirecting to external URLs. The paths to redirect are administered using instances of the Redirect content type. The paths that are redirected are independent of the path of the Redirect instance for a couple of reasons.

Firstly, since the portal object is not a BTree based folder it will begin to behave poorly if too many objects are added to it. Allowing the redirected paths independent from the location of the Redirect instances allows for many redirects without putting too many objects in the portal root.

Secondly, having the paths independent of the Redirect instance locations allows users to create redirect for paths that they can’t add content too. Keep in mind that this might be a bad thing for your site and can certainly be abused as a DOS attack of sorts.

If multiple redirects exist for the same path, the one with the more recent publication date will be preferred. Finally a redirect will never override an otherwise traversable URL. IOW, a redirect cannot override an actual content object, skin object, view, or anything else traversal. The redirect only occurs when a NotFound error would otherwise be raised.

Use a browser.

>>> from Products.Five import testbrowser
>>> browser = testbrowser.Browser()
>>> portal.error_log._ignored_exceptions = ()
>>> portal_url = portal.absolute_url()

Before a redirect is added, going to a non-existent URL will return the 404 page.

>>> browser.open(portal_url+'/foo')
Traceback (most recent call last):
HTTPError: HTTP Error 404: Not Found
>>> browser.open(portal_url+'/bar')
Traceback (most recent call last):
HTTPError: HTTP Error 404: Not Found

Open another browser and login as a user who can add Redirects.

>>> from Products.PloneTestCase import ptc
>>> member_browser = testbrowser.Browser()
>>> member_browser.handleErrors = False
>>> member_browser.open(portal.absolute_url())
>>> member_browser.getLink('Log in').click()
>>> member_browser.getControl(
...     'Login Name').value = ptc.default_user
>>> member_browser.getControl(
...     'Password').value = ptc.default_password
>>> member_browser.getControl('Log in').click()
>>> member_browser.open(portal_url+'/Members/test_user_1_')

Add a redirect. Set the “Local Path” field to the path that should be redirected from. The local path is always rooted at the portal. Set the “URL” field to the URL that should be redirected to.

>>> member_browser.getLink(url='createObject?type_name=Redirect').click()
>>> member_browser.getControl('Title').value = 'Foo Redirect Title'
>>> member_browser.getControl('Local Path').value = '/foo'
>>> member_browser.getControl('URL').value = '/plone/events'
>>> member_browser.getControl('Save').click()
>>> print member_browser.contents
<...
...Changes saved...
...Foo Redirect Title...
...Local Path...
.../foo...
...URL...
.../events...

When the redirect is not accessible to the user visiting the local path, such as when the workflow of the redirect forbids it, the redirect will not occur.

>>> foo_redirect = portal.Members.test_user_1_['foo-redirect-title']
>>> portal.portal_workflow.getInfoFor(
...     foo_redirect, 'review_state')
'private'
>>> browser.open(portal_url+'/foo')
Traceback (most recent call last):
HTTPError: HTTP Error 404: Not Found

Once the redirect is accessible, the user visiting the local path is redirected to the remote URL.

>>> self.loginAsPortalOwner()
>>> portal.portal_workflow.doActionFor(foo_redirect, 'publish')
>>> self.logout()

Use a VHM style URL to simulate a virtual hosting environment.

>>> browser.open('http://nohost/VirtualHostBase/http/nohost'
...              '/VirtualHostRoot/plone/foo/')
>>> browser.url
'http://nohost/plone/events'

A local path that has no redirect still returns the 404 page.

>>> browser.open(portal_url+'/bar')
Traceback (most recent call last):
HTTPError: HTTP Error 404: Not Found

Changelog

0.5 - 2010-11-10

  • Local paths with two or more non-existent segments didn’t work, because traversal stopped at the first non-existent segment and then request.URL would return this truncated path, so that no match would result when querying the catalog. Changed the view to use ACTUAL_URL instead, which does return the actual URL used.

0.4 - 2009-06-03

  • The fallback to plone’s standard_error_message was AQ wrapped in the plone_templates skin folder so that skin precedence was being ignored which, for example, didn’t allow for overriding default_error_message

0.3 - 2008-11-14

  • Add support for VHM

0.2 - 2008-11-12

  • Remove accidental commit from development

0.1 - 2008-11-11

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

collective.redirect-0.5.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file collective.redirect-0.5.tar.gz.

File metadata

File hashes

Hashes for collective.redirect-0.5.tar.gz
Algorithm Hash digest
SHA256 85d900e421c1ca431aa39dfb8945f8ddb5f1af27e83e5472b0803d6efee47527
MD5 14d91ed432920823cdb351eec6f919f6
BLAKE2b-256 e620ddb8bc72d9d18947f2dea9c8973a13b0bd36d83604e4be79e72378ee344d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page