views:

169

answers:

4

Hello

I am running my django project from subfolder of a website. Lets say the address where my project is meant to open from is.

http://example.com/myproject/

the myproject folder is root folder for my user account. In that folder i have fcgi script that starts my project. The .htaccess file in the folder contains this:

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

The trouble is, that at some cases, instead of redireting user to page like

http://example.com/myproject/social/someurl/

it redirects to

http://example.com/social/someurl/

which does not work. What i want to know is how to fix this problem.

Redirects in django-socialauth (github.com/uswaretech/Django-Socialauth), socialauth.views.py line 177 redirects without /myproject/, similar to the generic example above. I also use django cms2.0 in the project and it redirects user at admin auth to example.com/en/myproject/admin/, not example.com/myproject/en/admin. But that could be django cms's problem.

Is this kind of behaviour django problem and i should change it with urconf and add myproject to all urls, or should i do this with .htaccess? I found similar question, which, sadly, remains unanswered: http://stackoverflow.com/questions/2321154/how-to-write-htaccess-if-django-project-is-in-subfolder-and-subdomain

Alan.

A: 

What if you try

RewriteRule ^(myproject/.*)$ mysite.fcgi/$1 [QSA,L]
mojbro
Nope, that does not work. I'm not sure what this is doing exactly, but this kind of change results in me getting error that says - that i do not have permission to enter folder.. whatever this folder is...
Zayatzz
A: 

Set the RewriteBase:

RewriteEngine On
RewriteBase /myproject/
toscho
A: 

It's seems that django-cms-2.0 add the locale prefix to the url using the middleware level. Very well indeed.

But what's more interesting is that they prefix all of the url using resolve('pages-root')

So, you might be able to do this in the urls.py instead...

if not settings.DEBUG:
    urlpatterns += patterns('',
       url(r'^myproject/$', details, {'slug':''}, name='pages-root')
    )

Just make sure that you append the above urlpatterns before the cms.urls.

Bird
To be truthful i have not been able to test the replies, other than the one written by toscho. It seems to be working for now, but i have not had any time at all to test it throughly. But since Bird went through so much trouble to write this urlrewriting code for me, im going to accept this one as a working answet.
Zayatzz
A: 

In /urls_production.py

from django.conf.urls.defaults import *
urlpatterns = patterns('', 
    (r'^myproject/', include('urls')),
)

In /settings_production.py

from settings import *
ROOT_URLCONF = 'urls_production'

Make sure you set DJANGO_SETTINGS_MODULE to settings_production in the server environment.

Bird
I have a quick look at django-cms-2.0 multilingual modue. Since, they add the locale prefix right before django send the response to the browser. So, you might want to try my another answer instead.
Bird