Comments on: Django domain redirect middleware http://eikke.com/django-domain-redirect-middleware/ 'cause this is what I do Tue, 04 Dec 2012 00:03:23 +0000 hourly 1 http://wordpress.org/?v=3.4.1 By: Nicolas http://eikke.com/django-domain-redirect-middleware/comment-page-1/#comment-72281 Nicolas Wed, 28 Mar 2012 11:26:41 +0000 http://eikke.com/2007/12/26/django-domain-redirect-middleware/#comment-72281 oh and say host = request.get_host().split(':')[0] above there oh and say host = request.get_host().split(‘:’)[0] above there

]]>
By: Nicolas http://eikke.com/django-domain-redirect-middleware/comment-page-1/#comment-72279 Nicolas Wed, 28 Mar 2012 09:59:15 +0000 http://eikke.com/2007/12/26/django-domain-redirect-middleware/#comment-72279 Thanks a lot! If you're running Django on a non-default port, you might want to add the port number to the newly constructed URI: new_uri = '%s://%s%s%s%s' % ( request.is_secure() and 'https' or 'http', site.domain, (":" + request.META["SERVER_PORT"]) if request.META["SERVER_PORT"]!=80 else "", urlquote(request.path), (request.method == 'GET' and len(request.GET) > 0) and '?%s' % request.GET.urlencode() or '' ) Thanks a lot!
If you’re running Django on a non-default port, you might want to add the port number to the newly constructed URI:

new_uri = ‘%s://%s%s%s%s’ % (
request.is_secure() and ‘https’ or ‘http’,
site.domain,
(“:” + request.META["SERVER_PORT"]) if request.META["SERVER_PORT"]!=80 else “”,
urlquote(request.path),
(request.method == ‘GET’ and len(request.GET) > 0) and ‘?%s’ % request.GET.urlencode() or ”
)

]]>
By: trd http://eikke.com/django-domain-redirect-middleware/comment-page-1/#comment-65139 trd Tue, 29 Nov 2011 11:02:06 +0000 http://eikke.com/2007/12/26/django-domain-redirect-middleware/#comment-65139 Does the last solution of Nicolas keep the whole URL? For example if I'm poiting to http://website.org/cars/view/1/, I want to redirect to http://www.website.org/cars/view/1/, right? Does the last solution of Nicolas keep the whole URL?

For example if I’m poiting to http://website.org/cars/view/1/, I want to redirect to http://www.website.org/cars/view/1/, right?

]]>
By: Sagi http://eikke.com/django-domain-redirect-middleware/comment-page-1/#comment-50105 Sagi Fri, 13 May 2011 14:53:11 +0000 http://eikke.com/2007/12/26/django-domain-redirect-middleware/#comment-50105 The forum is a bihrtger place thanks to your posts. Thanks! The forum is a bihrtger place thanks to your posts. Thanks!

]]>
By: Martin http://eikke.com/django-domain-redirect-middleware/comment-page-1/#comment-37338 Martin Thu, 08 Jul 2010 08:34:43 +0000 http://eikke.com/2007/12/26/django-domain-redirect-middleware/#comment-37338 I just used your solution, it works flawlessly. Thanks ! I know I could have used apache mod_rewrite instead, but I felt more secure with your solution, since I understand django/python much better. I just used your solution, it works flawlessly. Thanks !

I know I could have used apache mod_rewrite instead, but I felt more secure with your solution, since I understand django/python much better.

]]>
By: Nicolas http://eikke.com/django-domain-redirect-middleware/comment-page-1/#comment-26 Nicolas Fri, 28 Dec 2007 00:28:17 +0000 http://eikke.com/2007/12/26/django-domain-redirect-middleware/#comment-26 Vincent: my solution also uses a HTTP 301 (a HttpResponsePermanentRedirect also translates to a HTTP 301 reply). One of the main benefits is it doesn't force you to use multiple vhosts, which is not always possible in shared hosting environments. By the way, your solution could be simplified by using something like <pre>Redirect permanent / http://foo.bar/</pre> in your Apache configuration, instead of pulling in mod_rewrite ;-) Vincent: my solution also uses a HTTP 301 (a HttpResponsePermanentRedirect also translates to a HTTP 301 reply). One of the main benefits is it doesn’t force you to use multiple vhosts, which is not always possible in shared hosting environments.

By the way, your solution could be simplified by using something like

Redirect permanent / http://foo.bar/

in your Apache configuration, instead of pulling in mod_rewrite ;-)

]]>
By: Vincent van Adrighem http://eikke.com/django-domain-redirect-middleware/comment-page-1/#comment-25 Vincent van Adrighem Thu, 27 Dec 2007 23:57:20 +0000 http://eikke.com/2007/12/26/django-domain-redirect-middleware/#comment-25 Why not use virtual hosts with rewriterules? If you're using apache anyway, then this is the most elegant solution IMHO. You want every request to go to www.somesite.net, but used to have www.oldsite.org, then set up a virtual host on www.oldsite.org containing nothing but a rewriterule: RewriteEngine On RewriteRule ^(.*)$ http://www.somesite.net/$1 [R=permanent] That way, client software even gets a 301 signal, giving the browser the possibility to automatically update your bookmarks. Why not use virtual hosts with rewriterules?
If you’re using apache anyway, then this is the most elegant solution IMHO.
You want every request to go to http://www.somesite.net, but used to have http://www.oldsite.org, then set up a virtual host on http://www.oldsite.org containing nothing but a rewriterule:

RewriteEngine On
RewriteRule ^(.*)$ http://www.somesite.net/$1 [R=permanent]

That way, client software even gets a 301 signal, giving the browser the possibility to automatically update your bookmarks.

]]>