Introduction
collective.scriptedredirect allows you to write HTTP 302 Moved Temporary and HTTP 301 Moved Permanently redirects for your Plone CMS site in Python code.
Benefits
The redirect logic is front-end web server independent: no need to touch variouos configuration files of Apache, Varnish or Nginx)
Python allows to write more complex logic for redirects easier - no regular expressions!
Python scripts in Plone have access to more complete state information: user logged in status, permissions, etc.
Usage
Installation
Add add-on in buildout.cfg:
eggs =
...
collective.scriptedredirect
Run buildout.
Install Scripted redirects in Python in Site Setup > Add-ons.
Doing redirects through the web
Edit redirect_handler in Zope Management Interface in your site root.
In the case of accident use ?no_redirect HTTP query parameter to override the redirecter and fix your site.
Doing redirects through the web
You can also register a browser view called redirect_handler. In this case, you write the redirect code in addon Python code and not through the web.
redirect_handler view is always preferred over redirect_handler script.
Example Python code in redirector.py:
class TestingRedirectHandler(object):
""" Redirect handler registered as a ``redirect_handler`` Zope 3 <browser:page>
"""
def __init__(self, context, request):
self.context = context
self.request = request
def __call__(self, url, host, port, path):
"""
:return: None if no redirect needed, otherwise a string full HTTP URL to the redirect target
:raise: zExceptions.Redirect or other custom redirect exception if needed
"""
# Simple example: always access site over www. domain prefix
if not url.startswith("http://www."):
return url.replace("http://", "http://www.")
# Don't redirect if we are already using www. prefix
return None
Example ZCML:
<browser:page
name="redirect_handler"
for="Products.CMFCore.interfaces.ISiteRoot"
layer="YOUR_ADDON_LAYER"
class=".redirector.TestRedirectHandler"
/>
Internals
collective.scriptedredirect hooks itself to Zope’s pre-traversal hook and is triggered before the request traverses into your Plone site in Zope application server.
Changelog
1.1.1 (2013-04-14)
Fixed .rst title levels for PyPi [miohtama]
1.1 (2013-04-14)
Added redirects via browser view support [miohtama]
Testing, Travis CI support [miohtama]
1.0
Initial development [miohtama]
Metadata
Release files for collective.scriptedredirect 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| collective.scriptedredirect-1.1.1.zip | 36.8 kB | Without provenance | Details for collective.scriptedredirect-1.1.1.zip |
Release files / collective.scriptedredirect-1.1.1.zip
| Download URL | collective.scriptedredirect-1.1.1.zip |
|---|---|
| Size | 36.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03868027e960ce508c6c9c08e140b3f6b7b4b7768280735450ae6685fdac1345
|
|
BLAKE2b-256 checksum How to use checksums |
fbea42594eb3176bc285c59f969c905fea15f220c144cd1cfbbae27cb6b7f95b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for collective.scriptedredirect 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.