views:

30

answers:

2

I am trying to setup a URL redirect for a Q&A site I am setting up for Boat Repairs. I want boatrepaired.com to go to www.boatrepaired.com. I am generally a php guy so I am a bit confused with python etc. used by OSQA. I added this to my apache conf file...

<Directory /opt/OSQA/>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^boatrepaired\.com [NC]
RewriteRule ^(.*)$ http://www.boatrepaired.com/$1 [L,R=301]
</Directory>

It somewhat works by sending boatrepaied.com to ... www.boatrepaired.com/osqa.wsgi/

If I remove off the $1 on line 5 it works perfect except it redirects everyone back to the front page. Any help would be appreciated.

Thanks,

Chris

A: 

OSQA is based on Django, and Django can automatically do this for you (I am pretty sure this is enabled for OSQA by default).

If not, add this setting to your Django settings module:

If PREPEND_WWW is True, URLs that lack a leading “www.” will be redirected to the same URL with a leading “www.”leading “www.”

And make sure the django.middleware.common.CommonMiddleware is enabled.

leoluk
PERFECT! Thanks!
Chris Edwards
A: 

Why not fix this entirely in apache:

<VirtualHost ..>
    ServerName boatrepaired.com

    Redirect permanent / http://www.boatrepaired.com/ 
</VirtualHost>

<VirtualHost ..>
    ServerName www.boatrepaired.com

    ... basic wsgi / django config ...
</VirtualHost>

So separate vhosts for both domains, with permanent redirects from the "wrong" one to the correct one. It will work for all paths within the domain, not just /

Ivo van der Wijk