Forums

How to redirect from www.mydomain.com to www.mydomain.com/index

Hi,

I have just got my first Django powered site up and running (thanks guys btw, the deployment couldn't have gone any smoother) I have hopefully a quick question that I am pretty sure has been asked a million times before but I must be using the wrong search terms!

The first page of my app is www.mydomain.com/index so if visitors arrive at www.mydomain.com I would like them redirected to www.mydomain.com/index automatically. How do I achieve this?

Thanks in advance.

Ian

Hi there -- glad PythonAnywhere's working well for you! :-)

The quickest way to do the redirect is probably to put this in your top-level urls.py:

url(r'^$', lambda r: HttpResponseRedirect("/index")),

You'll need this import at the top of the file too:

from django.http import HttpResponseRedirect

Perfect! Thanks again for your help much appreciated.

Regards

Ian