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

时间:2017-10-12 18:18:24

标签: django apache .htaccess mod-rewrite fastcgi

我想将www.myapp.com转发给myapp.com

我目前的htaccess

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

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

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

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

1 个答案:

答案 0 :(得分:0)

您必须先重定向:

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/$1
# The following two lines are for FastCGI:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ application.fcgi/$1 [QSA,L]