Opened 14 years ago

Closed 13 years ago

#13625 closed (worksforme)

FORCE_SCRIPT_NAME bug

Reported by: liangent Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm using FastCGI with the configuration:

FORCE_SCRIPT_NAME = '/path'

In rewrite rules, "/path/something" is rewritten to "/path/site.fcgi/something" ("something" can be blank) and "/path" is rewritten to "/path/site.fcgi"

If I visit "/path/", "^$" is matched from urlconf, which is correct.
If I visit "/path", it looks "^path$" is trying to be matched from urlconf, which is incorrect.

Change History (3)

comment:1 by Ramiro Morales, 13 years ago

Resolution: worksforme
Status: newclosed

I can't reproduce this with the following setup:

  • Lighttpd (I assume it is the web server you are using because yopu don't tell us bout it and it's one that needs the use of the FORCE_SCRIPT_NAME setting.)
  • Django trunk as of now.

with the following relevant configuration:

setting.py:

...
FORCE_SCRIPT_NAME = '/path'
...

lighttpd config:

fastcgi.server = (
    "/mysite.fcgi" => (
        "main" =>
        (
            "socket" => "/foo/mysite.sock",
            "check-local" => "disable"
        )
    )
)

alias.url = (
    "/static/admin" => "/path/to/the/django/checkout/django/contrib/admin/media/",
)

url.rewrite-once = (
    "^(/static/admin.*)$" => "$1",
    "^/path(/.*)$" => "/mysite.fcgi$1",

When the web browser access "/path" the request doesn't even reach the Django realm, it is lighttpd the one that isn't finding a match for that path in its own configuration and showing its 404 page.

If we add a rewrite rule for "/path" so it comes before the one we already have things work correctly (web browser access to both "/path" and "/path/" shows the Django view wired to the r'^$' expression in the main urls.py):

url.rewrite-once = (
    "^(/static/admin.*)$" => "$1",
     "^/path$" => "/mysite.fcgi",
    "^/path(/.*)$" => "/mysite.fcgi$1",
)

Note this ws what you've described but in the right order so the "^/path$" entry matches first.

At this point it would be extremely helpful if you post the configuration files you are using (specially the Web server rewrite rules you describe in English). Please reopen this ticket only if you can provide these details about your setup.

Also, I don't know if it is wise to to configure the web server to rewrite accesses to "/foo/" to something underneath that "/foo" (e.g. "/path/something" => "/path/site.fcgi/something") isn't risk of recursive behavior there?.

comment:2 by liangent, 13 years ago

Resolution: worksforme
Status: closedreopened

Zeus Web Server.

Rewrite script was like:

match URL into $ with ^/path(.*)
if matched
        set URL = /path/site.fcgi$1
endif

I had to change it to the following to make it work:

match URL into $ with ^/path/?(.*)
if matched
        set URL = /path/site.fcgi/$1
endif

Other configurations guarantee that only /path and /path/something are dispatched here (ie. no /pathsomething).

comment:3 by Ramiro Morales, 13 years ago

Resolution: worksforme
Status: reopenedclosed

I rewrote the lighttpd rewrite rule to almosy completely mimic the first Zeus Web server snippet you posted, including setting the virtual bucket mysite.fcgi full path to "/path/mysite.fcgi". The only detail I had to add is the anchor $ at the end (for you case the rule would need to be "match URL into $ with ^/path(.*)$")
If I don't do that, again the 404 page shown isn't Django's one but Web server's.

fastcgi.server = (
    "/mysite.fcgi" => (
        "main" =>
        (
            "socket" => "/foo/mysite.sock",
            "check-local" => "disable"
        )
    )
)

alias.url = (
    "/static/admin" => "/home/ramiro/django/upstream/django/contrib/admin/media/",
)

url.rewrite-once = (
    "^(/static/admin.*)$" => "$1",
 access to both "/path" and "/path/" shows the Django view wired to the r'^$' expression in the main urls.py): 
    "^/path(.*)$" => "/path/mysite.fcgi$1",
)

And things work as expected: Access to both "/path" and "/path/" shows the Django view wired to the r'^$' RE in the main urls.py, access to the admin app in /path/admin works without problems (logging in, CSS, JS images media serving, model CRUD, logging out).

Because all the above, I conclude this is a problem with the web server setup and therefore I'm closing this ticket.

Note: See TracTickets for help on using tickets.
Back to Top