I have an apache configure with:

WSGIPythonHome /envpath/venv
WSGIPythonPath /app_path/app_directory

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /subdir/static/ /app_path/app_directory/static/

    WSGIScriptAlias /subdir /app_path/app_directory/wsgi.py

    <Directory /app_path/app_directory>
        <Files wsgi.py>
            Order deny,allow
            Allow from all
            Require all granted
    <Directory /app_path/app_directory/static>
        Order deny,allow
        Allow from all
        Require all granted


With this configuration, if I access locahost/subdir/accounts/login/ everything works fine, but if I access locahost/subdir/ it redirects me to locahost/accounts/login/ which returns a 404 error.

I have already tried to set LOGIN_REDIRECT_URL = '/subdir/accounts/login/', FORCE_SCRIPT_NAME = '/subdir', BASE_URL = '/subdir' and SUB_SITE = "/subdir/" in settings.py without any diference.

I also tried to append urlpatterns = [url(r'subdir/', include(urlpatterns))] at the end of urls.py but then it gives me a dango's 404 error saying that /accounts/login didn't match '/subdir/

Any idea about how to make django redirect with the correct subdirectory?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.