WebFaction
Community site: login faq

I have two domains:

  example.com
  example.org

and have the "django 1.3/mod_wsgi 3.3/python 2.7" application installed at the root of both of these domains. Without a url rewrite, everything works just fine on both domains. However, I would like to redirect all example.org urls to example.com. Here is my .htaccess file:

  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^example.org [NC]
  RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

However, when I go to http://example.org, I am redirected to:

  http://example.com/myproject.wsgi/

Similarly, going to http://example.org/blah takes me to:

  http://example.com/myproject.wsgi/blah/

Two questions:

  1. Why is this happening?
  2. How do I make it so that the redirects look exactly as if the user had typed .com instead of .org?

asked 05 Jul '11, 01:21

lewstherin
313
accept rate: 0%

edited 05 Jul '11, 01:21


Where do you have the .htaccess file located? Are you using a second 'Static/CGI/PHP" app as outlined here?

http://docs.webfaction.com/software/static.html#redirect-a-domain-with-a-static-cgi-php-app

Since Django is designed to work with the URLs you might have issues effectively using mod_rewrite to dynamically rewrite.

The stable/simple way of doing this is to point both domains to the 1 app using the website record within the control panel.

permanent link

answered 05 Jul '11, 02:02

johns ♦♦
5.2k211
accept rate: 22%

Creating a second app seems like overkill. My present configuration is that I have a single application with both domains associated to it. The .htaccess file is in ~/webapps/app_name/.htaccess. Also, I don't understand why Django should be an issue here. Isn't the point of the url rewrite that it should take effect BEFORE django does whatever it does?

(05 Jul '11, 02:45) lewstherin

Try moving the code from that location to the apache config file directly. It is located in ~/webapps/appname/apache2/conf/httpd.conf. Having it in that directory might be what is causing the issue. To understand some of the issues with using mod_rewrite with Django this post explains some issues,

https://code.djangoproject.com/wiki/django_apache_and_mod_rewrite

What Django has to do with it is at a technical level it can get complex when configuring it this way.

Why will using the control panel and editing the website record to point both domains to the same app using the front-end nginx server not work? As stated that is the easiest way,

http://docs.webfaction.com/user-guide/websites.html#creating-a-website
(05 Jul '11, 03:01) johns ♦♦

There is a guide on stackoverflow that covers some more options,

http://stackoverflow.com/questions/2285879/how-do-i-redirect-domain-com-to-www-domain-com-under-django
(05 Jul '11, 03:09) johns ♦♦

Moving it from the .htaccess file to httpd.conf worked wonderfully. I also had to change the rewrite rule due to some trailing slash issues:

 RewriteRule ^(.*)$ http://example.com$1 [R=301,L]
(05 Jul '11, 04:18) lewstherin
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×901
×62
×13

question asked: 05 Jul '11, 01:21

question was seen: 3,951 times

last updated: 05 Jul '11, 04:18

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2016 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM