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

  • SEARCH
  • Home
  • 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 617075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:23:43+00:00 2026-05-13T18:23:43+00:00

How do I go about redirecting all requests for domain.com/… to www .domain.com/… with

  • 0

How do I go about redirecting all requests for domain.com/… to www.domain.com/… with a 301 in a django site?

Obviously this can’t be done in urls.py because you only get the path part of the URL in there.

I can’t use mod rewrite in .htaccess, because .htaccess files do nothing under Django (I think).

I’m guessing something in middleware or apache conf?

I’m running Django on a Linux server with Plesk, using mod WSGI

  • 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-13T18:23:43+00:00Added an answer on May 13, 2026 at 6:23 pm

    The WebFaction discussion someone pointed out is correct as far as the configuration, you just have to apply it yourself rather than through a control panel.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com$
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    

    Put in .htaccess file, or in main Apache configuration in appropriate context. If inside of a VirtualHost in main Apache configuration, your would have ServerName be http://www.example.com and ServerAlias be example.com to ensure that virtual host handled both requests.

    If you don’t have access to any Apache configuration, if need be, it can be done using a WSGI wrapper around the Django WSGI application entry point. Something like:

    import django.core.handlers.wsgi
    _application = django.core.handlers.wsgi.WSGIHandler()
    
    def application(environ, start_response):
      if environ['HTTP_HOST'] != 'www.example.com':
        start_response('301 Redirect', [('Location', 'http://www.example.com/'),])
        return []
      return _application(environ, start_response)
    

    Fixing this up to include the URL within the site and dealing with https is left as an exercise for the reader. 🙂

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

Sidebar

Related Questions

So, I submitted an answer to this SO question about redirecting your site ,
I am currently redirecting to this: https://graph.facebook.com/oauth/authorize?client_id=305384546164461&redirect_uri=http://www.eeisi.com/bridge/auth.php&type=web_server&display=page&scope=publish_stream,%20user_about_me,%20user_likes,%20email I have no idea why I am
First of all this is not just about redirecting. I'm trying to understand the
I'm driving crazy about this, but I'm sure it's only a small thing.. All
About project: I'm trying to write CMS-like web-site on Java. Previously I used PHP
About 6 months ago I rolled out a site where every request needed to
This is the scenario: I have a list of about 5000 URLs which have
I've recently renamed some pages on my (sinatra-backed) site. I'm redirecting from the old
I want to redirect /about /about/ /about.html /about.html/ /weare/ /weare /weare.html /weare.html/ All these
Am redirecting urls from a legacy site, which gets me to a url like

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.