redirects.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. .. _redirects:
  2. =========
  3. Redirects
  4. =========
  5. .. module:: wagtail.contrib.redirects
  6. The ``redirects`` module provides the models and user interface for managing arbitrary redirection between urls and ``Pages`` or other urls.
  7. Installation
  8. ============
  9. The ``redirects`` module is not enabled by default. To install it, add ``wagtail.contrib.redirects`` to ``INSTALLED_APPS`` and ``wagtail.contrib.redirects.middleware.RedirectMiddleware`` to ``MIDDLEWARE`` in your project's Django settings file.
  10. .. code-block:: python
  11. INSTALLED_APPS = [
  12. # ...
  13. 'wagtail.contrib.redirects',
  14. ]
  15. MIDDLEWARE = [
  16. # ...
  17. # all other django middlware first
  18. 'wagtail.contrib.redirects.middleware.RedirectMiddleware',
  19. ]
  20. This app contains migrations so make sure you run the ``migrate`` django-admin command after installing.
  21. Usage
  22. =====
  23. Once installed, a new menu item called "Redirects" should appear in the "Settings" menu. This is where you can add arbitrary redirects to your site.
  24. Page model recipe of to have redirects created automatically when changing a page's slug, see :ref:`page_model_auto_redirects_recipe`.
  25. For an editor's guide to the interface, see :ref:`managing_redirects`.
  26. Management commands
  27. ===================
  28. import_redirects
  29. ----------------
  30. .. code-block:: console
  31. $ ./manage.py import_redirects
  32. This command imports and creates redirects from a file supplied by the user.
  33. Options:
  34. - **src**
  35. This is the path to the file you wish to import redirects from.
  36. - **site**
  37. This is the **site** for the site you wish to save redirects to.
  38. - **permanent**
  39. If the redirects imported should be **permanent** (True) or not (False). It's True by default.
  40. - **from**
  41. The column index you want to use as redirect from value.
  42. - **to**
  43. The column index you want to use as redirect to value.
  44. - **dry_run**
  45. Lets you run a import without doing any changes.
  46. - **ask**
  47. Lets you inspect and approve each redirect before it is created.
  48. The ``Redirect`` class
  49. ======================
  50. .. automodule:: wagtail.contrib.redirects.models
  51. .. autoclass:: Redirect
  52. .. automethod:: add_redirect