I am trying to redirect the root of a Django site to the Django admin panel, and I basically started and started it. However, I noticed that if there is no slash in the project URL, the links on the page do not include the project folder, but instead try to find applications in the root of the site.
So, let's say I have a project fooand an application bar. If you visited http://server/foo/(with a trailing slash), everything will be fine, and the links on the page will go to http://server/foo/bar. However, if you visit http://server/foo, the generated links will go to http://server/barinstead, which generates a 404 error.
If I set WSGIScriptAliasto indicate /foo/instead /foo, this will result in a 404 error if I go to /foo. I tried to force the trailing slash to Apache conf using Redirect, but ended up creating a recursive redirect ( http://server/foo//////...). I have not tried to use the .htaccess file yet, but I suspect this could happen.
I tried the same in urls.py, however:
url(r'^$', redirect_to, {'url': '/'}),
url(r'^$', redirect_to, {'url': 'foo/'}),
url(r'^$', redirect_to, {'url': '/foo/'}),
I also tried just adding a slash to all of Django's urls:
url(r'^(.*)/', include(admin.site.urls))
But in the root folder of the project, it can’t match anything at all (although if you go to the application, it seems that it works fine).
I am using Apache 2.2 with mod_wsgi, here is the configuration:
Alias /static "C:/DJANGO~1/apps/django/django/contrib"
<Directory 'C:/DJANGO~1/apps/django/django/contrib'>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /foo "C:/Djangostack/apps/django/scripts/django.wsgi"
<Directory 'C:/Djangostack/apps/django/scripts'>
Order allow,deny
Allow from all
</Directory>
And this urls.py, which basically works:
urlpatterns = patterns('',
url(r'^', include(admin.site.urls)),
)
, APPEND_SLASH True, .