去网站 url 的 www 版本在 django 网站上收到 404
going to www version of site url receives 404 on django site
我可以毫无问题地到达我的网站的路线:http://example.com
当我转到 http://www.example.com 时出现 404 错误。
如何处理转到 www 并将用户传送到站点的路径?
我不认为这有关系,但这是我的 httpd.conf:
WSGISocketPrefix /var/run/wsgi
<VirtualHost *:80>
WSGIDaemonProcess example.com display-name=%{GROUP}
WSGIProcessGroup example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /example
WSGIScriptAlias / /example/wsgi.py
</VirtualHost>
Alias /static/ /example
<Directory /example>
Order deny,allow
Allow from all
</Directory>
WSGIPythonPath /example
<Directory /example>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
将settings.py中的ALLOWED_HOSTS改成这样
ALLOWED_HOSTS = ['www.example.com', 'example.com']
根据 Django 文档,ALLOWED_HOSTS 定义
A list of strings representing the host/domain names that this Django site can serve. This is a security measure to prevent an attacker from poisoning caches and triggering password reset emails with links to malicious hosts by submitting requests with a fake HTTP Host header, which is possible even under many seemingly-safe web server configurations.
我可以毫无问题地到达我的网站的路线:http://example.com
当我转到 http://www.example.com 时出现 404 错误。
如何处理转到 www 并将用户传送到站点的路径?
我不认为这有关系,但这是我的 httpd.conf:
WSGISocketPrefix /var/run/wsgi
<VirtualHost *:80>
WSGIDaemonProcess example.com display-name=%{GROUP}
WSGIProcessGroup example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /example
WSGIScriptAlias / /example/wsgi.py
</VirtualHost>
Alias /static/ /example
<Directory /example>
Order deny,allow
Allow from all
</Directory>
WSGIPythonPath /example
<Directory /example>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
将settings.py中的ALLOWED_HOSTS改成这样
ALLOWED_HOSTS = ['www.example.com', 'example.com']
根据 Django 文档,ALLOWED_HOSTS 定义
A list of strings representing the host/domain names that this Django site can serve. This is a security measure to prevent an attacker from poisoning caches and triggering password reset emails with links to malicious hosts by submitting requests with a fake HTTP Host header, which is possible even under many seemingly-safe web server configurations.