htaccess rewrite incorrectly appending URL with mod_wsgi config file path

I'm currently in the process of migrating domains [old_domain] -> [new_domain].

The problem arose when I came to the htaccess rules and the config file in /etc/httpd/conf/httpd.conf:

httpd.conf

AllowOverride All

Initially I could not find where to put the above to allow .htaccess rewrite rules to work and I'm still concerned that I may be incorrectly allowing it for all.

I've tried putting it in something like but to no effect:

<Directory "/path/to/django/project/">
    AllowOverride All
</Directory>

Once I did get the .htaccess file rewrites working (using the following) the URLs started returning something odd.

.htaccess in django project directory

RewriteEngine On
RewriteCond %{HTTP_HOST} !^old_domain.com/$ [NC]
RewriteRule ^(.*)$ http://new_domain.com/$1 [L,R=301]

URL sent

http://old_domain.com/news/

URL received

http://new_domain.com/apache/production.wsgi/news/

Nearly there... but can anyone suggest why this might be happening? I don't really want to be stripping out the /apache/production.wsgi/ on the new_domain side (unless this is expected?)

Thanks in advance.

Edit: One quick fix included using django's HttpResponsePermanentRedirect. Is this bad practice?

Answers


If you want to use the rewrite directive within your django folder then you need to enable overides. Otherwise they will be ignored:

http://httpd.apache.org/docs/current/mod/core.html#allowoverride

Hopefully this does the trick for the rewrite:

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} !^newdomain\.com 
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

Be sure to delimit the periods in the domain of you RewriteCond. In regex, . means "match all"


Need Your Help

Running a program from a byte array using VirtualAlloc?

c# runtime .net virtualalloc

I'm working on application SFX / Protector in C# and i want the protected assembly to be executed from a byte array instead of writing it to hard disk, in order to be much harder for reverse engine...

Consume a xml web-service jersey through a JQuery Ajax call

jquery ajax web-services jersey

I'm trying to call a jersey Webservice which returns xml data. The call is done with a jquery ajax call which has the following format: