Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6062737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:05:10+00:00 2026-05-23T09:05:10+00:00

Django has CommonMiddleware setup, which by default appends a slash to URLs that do

  • 0

Django has CommonMiddleware setup, which by default appends a slash to URLs that do not end with one.

For example:
(1) http://www.example.com/admin is rewritten to (2) http://www.example.com/admin/ if it detects in the URLconf that /admin/ exists.

However, I am getting the situation where instead of (2), I am getting (3) http://www.example.com//admin/ which gives me a 404 error.

Is this correct behaviour? What would be one way to resolve the 404 error?
Thanks a lot.

Note:
I am running on Django 1.3 + nginx + gunicorn.
I’ve tried running with Django 1.3 + nginx + apache + mod_wsgi and I’m getting (3) as well (so it’s not a webserver problem) but I don’t get the 404 error.

======================================================================

UPDATE:

The problem is with the nginx configuration, which I wrote to redirect HTTP requests to HTTPS.
The following is a sample of the nginx configuration with the error:

upstream django {
    server 127.0.0.1:8000;
}

server {
    listen  80; 
    server_name www.example.com;

    location / { 
        rewrite (.*) https://www.example.com/$1 permanent;
    }   
}

server {
    listen       443;
    server_name  www.example.com;

    ssl                  on;
    ssl_certificate      /home/user/certs/example.com.chained.crt;
    ssl_certificate_key  /home/user/certs/example.com.key;
    ssl_prefer_server_ciphers on;

    ssl_session_timeout  5m;

    location ~ ^/static/(.*)$ {
        alias /home/user/deploy/static/$1;
        access_log off;
        expires max;
    }

    location / {
        try_files $uri $uri/ @django_proxy;
    }

    location @django_proxy {
        proxy_pass          http://django;
        proxy_redirect      off;    
        proxy_set_header    Host                 $host;          
        proxy_set_header    X-Real-IP            $remote_addr;   
        proxy_set_header    X-Forwarded-For      $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Protocol    https;  
    }
}

What was happening was the CommonMiddleware was redirecting from https://www.example.com/admin to http://www.example.com/admin/. This hit nginx again, and a URL rewrite was done as specified in the config file to https://www.example.com/$1 where $1 is “/admin/”. This meant that the final URL was https://www.example.com//admin/.

To correct this, I changed the rewrite rule to:

server {
    listen  80; 
    server_name www.example.com;

    location / { 
        rewrite /(.*) https://www.example.com/$1 permanent;
    }   
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:05:10+00:00Added an answer on May 23, 2026 at 9:05 am

    “Is this correct behavior?” No, it’s not. In 4 years of Djangoing I’ve never seen this particular problem.

    One way of testing that the CommonMiddleware is causing this is to comment it out in your settings.py file, restart, and then see if you get the same behavior. It can also be instructive to use the standalone development server and stick print‘s in interesting places to see who is mangling it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.