Django 使用 fastcgi RewriteRule 将 www.domain.com 转发到 domain.com

Django forward www.domain.com to domain.com with fastcgi RewriteRule

我想转发www.myapp.commyapp.com

我当前的 htaccess

AddHandler fcgid-script .fcgi
RewriteEngine on
# Set up static content redirect:
RewriteRule static/(.+)$ myapp-folder/public/static/
# The following two lines are for FastCGI:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ application.fcgi/ [QSA,L]

我尝试在上面的内容中添加以下行

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

但它没有给我想要的输出。没有 fastcgi 我可以只替换这些行,因为我的应用程序依赖于它如何在不删除 fcgi 规则的情况下添加此转发。

您必须先重定向:

AddHandler fcgid-script .fcgi
RewriteEngine on

# www.myapp.com to -> myapp.com
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ http://myapp.com%{REQUEST_URI} [NE,R=301,L]

# Set up static content redirect:
RewriteRule static/(.+)$ myapp-folder/public/static/
# The following two lines are for FastCGI:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ application.fcgi/ [QSA,L]