Django 内部重定向

发布于 2024-09-04 21:09:56 字数 4108 浏览 2 评论 0原文

我有一个项目在我自己的开发计算机上(使用 mod_wsgi 为该项目提供服务)没有造成任何问题。在实时服务器(使用 mod_fastcgi)中,它会生成 500 个。

我的 url conf 是这样的:

# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
      url(r'^admin/', include(admin.site.urls)),
      url(r'^', include('jalka.game.urls')),
)

并且

# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *

from django.contrib.auth import views as auth_views

urlpatterns = patterns('jalka.game.views',
      url(r'^$',
            view = 'front',
            name = 'front',),
      url(r'^ennusta/(?P<game_id>\d+)/$',
            view = 'ennusta',
            name = 'ennusta',),
      url(r'^login/$',
            auth_views.login,
            {'template_name': 'game/login.html'},
            name='auth_login'),
      url(r'^logout/$',
            auth_views.logout,
            {'template_name': 'game/logout.html'},
            name='auth_logout'),
      url(r'^arvuta/$',
            view = 'arvuta',
            name = 'arvuta',),            
)

.htaccess 是这样的:

Options +FollowSymLinks 
RewriteEngine on
RewriteOptions MaxRedirects=10
# RewriteCond %{HTTP_HOST} . 
RewriteCond %{HTTP_HOST} ^www\.domain\.com
RewriteRule (.*) http://domain.com/$1 [R=301,L]

AddHandler fastcgi-script .fcgi

RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/fifa2010.fcgi/$1 [QSA,L]

RewriteCond %{HTTP_HOST} ^subdomain\.otherdomain\.eu$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/django.fcgi/$1 [QSA,L]

注意,我还使用相同的 .htaccess 设置了其他项目,并且该项目运行得很好,具有更复杂的 url 和视图

fifa2010.fcgi:

#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import sys, os

DOMAIN = "domain.com"
APPNAME = "jalka"

PREFIX = "/www/apache/domains/www.%s" % (DOMAIN,)

# Add a custom Python path.
sys.path.insert(0, os.path.join(PREFIX, "htdocs/django/Django-1.2.1"))
sys.path.insert(0, os.path.join(PREFIX, "htdocs"))
sys.path.insert(0, os.path.join(PREFIX, "htdocs/jalka"))


# Switch to the directory of your project. (Optional.)
os.chdir(os.path.join(PREFIX, "htdocs", APPNAME))

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "%s.settings" % (APPNAME,)

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

艾伦

编辑:I增加最大重定向并出现不同类型的错误:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)文件名太长:访问 /www/apache/domains/www.domain .com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com /htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs /cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi -bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin /fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010 .fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi /jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka / 失败

,看起来它不断重定向回自身,但至于为什么 - 我不知道。

编辑2-解决了! 最后,当我将 .htaccess 更改为此时,它开始工作:

RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) /cgi-bin/fifa2010.fcgi [QSA,L]

RewriteCond %{HTTP_HOST} ^subdomain\.otherdomain\.eu$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/django.fcgi/$1 [QSA,L]

I have one project that in my own development computer (uses mod_wsgi to serve the project) caused no problems. In live server (uses mod_fastcgi) it generates 500 though.

my url conf is like this:

# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
      url(r'^admin/', include(admin.site.urls)),
      url(r'^', include('jalka.game.urls')),
)

and

# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *

from django.contrib.auth import views as auth_views

urlpatterns = patterns('jalka.game.views',
      url(r'^

and .htaccess is like that:

Options +FollowSymLinks 
RewriteEngine on
RewriteOptions MaxRedirects=10
# RewriteCond %{HTTP_HOST} . 
RewriteCond %{HTTP_HOST} ^www\.domain\.com
RewriteRule (.*) http://domain.com/$1 [R=301,L]

AddHandler fastcgi-script .fcgi

RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/fifa2010.fcgi/$1 [QSA,L]

RewriteCond %{HTTP_HOST} ^subdomain\.otherdomain\.eu$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/django.fcgi/$1 [QSA,L]

Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views

fifa2010.fcgi:

#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import sys, os

DOMAIN = "domain.com"
APPNAME = "jalka"

PREFIX = "/www/apache/domains/www.%s" % (DOMAIN,)

# Add a custom Python path.
sys.path.insert(0, os.path.join(PREFIX, "htdocs/django/Django-1.2.1"))
sys.path.insert(0, os.path.join(PREFIX, "htdocs"))
sys.path.insert(0, os.path.join(PREFIX, "htdocs/jalka"))


# Switch to the directory of your project. (Optional.)
os.chdir(os.path.join(PREFIX, "htdocs", APPNAME))

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "%s.settings" % (APPNAME,)

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

Alan

EDIT:I increased maximum redirects and got different kind of error:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed

it looks like it keeps redirecting back to itself, but as to why - i have no idea.

Edit2- Solved!
In the end, when i changed my .htaccess to this it started working:

RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) /cgi-bin/fifa2010.fcgi [QSA,L]

RewriteCond %{HTTP_HOST} ^subdomain\.otherdomain\.eu$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/django.fcgi/$1 [QSA,L]
, view = 'front', name = 'front',), url(r'^ennusta/(?P<game_id>\d+)/

and .htaccess is like that:


Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views

fifa2010.fcgi:


Alan

EDIT:I increased maximum redirects and got different kind of error:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed

it looks like it keeps redirecting back to itself, but as to why - i have no idea.

Edit2- Solved!
In the end, when i changed my .htaccess to this it started working:


,
            view = 'ennusta',
            name = 'ennusta',),
      url(r'^login/

and .htaccess is like that:


Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views

fifa2010.fcgi:


Alan

EDIT:I increased maximum redirects and got different kind of error:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed

it looks like it keeps redirecting back to itself, but as to why - i have no idea.

Edit2- Solved!
In the end, when i changed my .htaccess to this it started working:


,
            auth_views.login,
            {'template_name': 'game/login.html'},
            name='auth_login'),
      url(r'^logout/

and .htaccess is like that:


Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views

fifa2010.fcgi:


Alan

EDIT:I increased maximum redirects and got different kind of error:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed

it looks like it keeps redirecting back to itself, but as to why - i have no idea.

Edit2- Solved!
In the end, when i changed my .htaccess to this it started working:


,
            auth_views.logout,
            {'template_name': 'game/logout.html'},
            name='auth_logout'),
      url(r'^arvuta/

and .htaccess is like that:


Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views

fifa2010.fcgi:


Alan

EDIT:I increased maximum redirects and got different kind of error:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed

it looks like it keeps redirecting back to itself, but as to why - i have no idea.

Edit2- Solved!
In the end, when i changed my .htaccess to this it started working:


,
            view = 'arvuta',
            name = 'arvuta',),            
)

and .htaccess is like that:

Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views

fifa2010.fcgi:

Alan

EDIT:I increased maximum redirects and got different kind of error:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed

it looks like it keeps redirecting back to itself, but as to why - i have no idea.

Edit2- Solved!
In the end, when i changed my .htaccess to this it started working:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情稳全场 2024-09-11 21:09:56

这似乎是您的问题:

RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/fifa2010.fcgi/$1 [QSA,L]

让我们以请求 http://jalka.domain.com/jalka.html 为例。如果 jalka.html 不存在,您的代码会将您重定向到 http://jalka.domain.com/cgi-bin/fifa2010.fcgi/jalka.html。当 Apache 查找 /cgi-bin/fifa2010.fcgi/jalka.html 时,它不会找到它,因为 fifa2010.fcgi 是一个文件,而不是一个目录。因此,您会被重定向到 http://jalka.domain.com/cgi-bin/fifa2010.fcgi/cgi-bin/fifa2010.fcgi/jalka.html。再次,找不到该文件。

这就是您最终出现文件名太长错误的原因,因为此重定向会一遍又一遍地发生。

This seems to be your problem:

RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/fifa2010.fcgi/$1 [QSA,L]

Lets take an example of a request to http://jalka.domain.com/jalka.html If jalka.html does not exist, your code redirects you to http://jalka.domain.com/cgi-bin/fifa2010.fcgi/jalka.html. When Apache looks for /cgi-bin/fifa2010.fcgi/jalka.html it won't find it, because fifa2010.fcgi is a file, not a directory. As a result, you get redirected to http://jalka.domain.com/cgi-bin/fifa2010.fcgi/cgi-bin/fifa2010.fcgi/jalka.html. Yet again, this file cannot be found.

This is how you end up with a filename too long error, because this redirect happens over and over again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文