{% extends 'admin/base_site.html' %} {% load i18n pinmok_admin_tags %} {% block need_page_header %}{% endblock %} {% block content %}

{% translate "URL Alias Feature Setup" %}

{% translate "To enable the URL alias feature, you need to add one line to your project's root urls.py file. Without this, aliases will be saved but will not work." %}

{% translate "Step 1: Import the view" %}

{% translate "Add the following import at the top of your root urls.py:" %}


                from pinmok.padmin.views import alias_resolver
            

{% translate "Step 2: Add the URL pattern" %}

{% translate "Add the following line inside your urlpatterns list. It must be the last item, after all other patterns:" %}


                path('<path:alias>', alias_resolver,
                name='alias_resolver'),
            

{% translate "Complete example" %}

{% translate "Your urls.py should look like this:" %}

from django.conf import settings
from django.conf.urls.static import static
from django.urls import path, include

from pinmok.padmin.views import alias_resolver
from pinmok.core.sites import site

urlpatterns = [
    path('admin/', site.urls),
    path('content/', include('pinmok.content.urls')),
    path('<path:alias>', alias_resolver, name='alias_resolver'), # must be last
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

{% translate "Why must it be last?" %}

{% blocktranslate trimmed %} Django matches URL patterns in order, from top to bottom. The alias pattern matches any URL, so if it is placed before other patterns, it will intercept all requests and your site will stop working correctly. Always keep it as the last item in urlpatterns. {% endblocktranslate %}

{% translate "How does it work?" %}

{% blocktranslate trimmed %} When a visitor accesses an alias URL (e.g. /news/), Django first tries to match all regular URL patterns. If none match, the alias resolver checks the alias table. If a matching alias is found and is active, the request is forwarded internally to the real URL. The visitor's browser address bar keeps showing the alias URL. {% endblocktranslate %}

{% translate "After adding the line to urls.py, restart your development server. The warning on this page will disappear automatically once the configuration is detected." as tip_note %} {% alert tip_note 'info' %} {% translate "Make sure there are no duplicate aliases. If two aliases are identical, only the first one saved will be used. The second one will cause a validation error when you try to save it." as tip_warning %} {% alert tip_warning 'warning' %}
{% endblock %}