简体   繁体   English

在Python Django中从HTTP重定向到HTTPS

[英]Redirect from HTTP to HTTPS in Python Django

I want to redirect the python and django websites from http to https . 我想将pythondjango网站从http重定向到https When I'm using the SECURE_SSL_REDIRECT = True in settings.py , I'm getting the folder structure: 当我在settings.py使用SECURE_SSL_REDIRECT = True时,我得到了文件夹结构:

图片

Are you using apache? 你在使用apache吗?

Try this on your .htacess inside www folder. 在.htacess里面的www文件夹中试试这个。

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

supposing that: 假设:

  1. you are using apache2 ; 你正在使用apache2 ;
  2. you are starting from the default-ssl.conf file which, if you are using a debian-like distro, is located in the directory /etc/apache2/sites-available ; 你是从default-ssl.conf文件开始的,如果你使用类似debian-like发行版,它位于/etc/apache2/sites-available ;
  3. you are serving your django application using mod_wsgi , having modified your default-ssl.conf as described in this howto 你正在使用的服务您的Django应用程序mod_wsgi的,具有修饰您的default-ssl.conf在描述这个HOWTO

you could try defining a permanent redirect to https in the <VirtualHost *:80> directive, always in your default-ssl.conf , as shown below: 您可以尝试在<VirtualHost *:80>指令中定义永久重定向到https,始终在default-ssl.conf ,如下所示:

<IfModule mod_ssl.c>
    <VirtualHost *:80>
        ServerName your-server.name
        Redirect permanent / https://your-server.name
    </VirtualHost>

    <VirtualHost _default_:443>
        ServerName your-server.name
        ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM