Configuring htaccess with django and apache

.htaccessapache-2.2django

I am trying to configure my apache server with django. I am having issues matching urls to their views and am not quite sure of the cause of the problem. I have the following configuration:

.htaccess:

AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ cyber.fcgi/ [QSA,L]

urls.py:

from django.conf.urls import patterns, include, url
from django.conf import settings
from views import index, test
from os import path
urlpatterns = patterns('',
    (r'^$', index),
    (r'^test/$', test),
)

The problem I am encountering is that all urls that do not start with /cyber.fcgi/ automatically match the index view. For testing, I am printing the url that view sees:

www.example.com/test/           <= matches index with url /test/
www.example.com/test            <= matches index with url /tes/
www.example.com/cyasdasd/123    <= matches index with url /cyasdasd/12/
www.example.com/cyber.fcgi/     <= matches index with url /cyber.fcgi/
www.example.com/cyber.fcgi/test <= matches test with url /cyber.fcgi/test/
www.example.com/cyber.fcgi/asd  <= no match

It appears that the correct behavior only occurs when /cyber.fcgi is called directly. I am assuming this is a problem with RewriteRule ^(.*)$ cyber.fcgi/ [QSA,L] but I am not entirely sure nor do I know how to fix it. Any help would be appreciated.

Best Answer

RewriteRule ^(.*)$ cyber.fcgi/$1 [QSA,L]

Missing $1 at the end.