Django: bad redirect request syntax with Apache mod_rewrite

My Django runs on port 8000 and Apache on 80. I configured the following rewrite rule in apache to redirect to django:

RewriteRule ^/?checkout/ http://%{HTTP_HOST}:8000/checkout/ [L,QSA]

If you open the browser in the browser, it works fine and redirects.

However, an external client (which works well when connecting to django directly without apache) always causes a Bad Request syntax error on the Django server. Sherry from Django Log. It looks like Apache automatically adds Content-length materials to the request, why?

[05/Mar/2014 18:01:35] code 400, message Bad request syntax ('GET /checkout/wx_signature?signature=b226bb8f6e9ce2fdecb752c6808a979c62e235f7&echostr=5987526888415258224&timestamp=1394042480&nonce=1394079741Content-Length: 445Connection: closeContent-Type: text/html; charset=iso-8859-1 HTTP/1.0')
+4
source share
2 answers

tl; dr: ​​ " ". HTTP-, , , .

, , .


Django:

[05/Mar/2014 18:01:35] code 400, message Bad request syntax ('GET /checkout/wx_signature?signature=b226bb8f6e9ce2fdecb752c6808a979c62e235f7&echostr=5987526888415258224&timestamp=1394042480&nonce=1394079741Content-Length: 445Connection: closeContent-Type: text/html; charset=iso-8859-1 HTTP/1.0')

" 400" HTTP 400. , HTTP- . , Django , .


, , , :

GET /checkout/wx_signature?[SIGNATURE REMOVED]Content-Length: 445Connection: closeContent-Type: text/html; charset=iso-8859-1 HTTP/1.0

HTTP-.


RFC2616 5.1:

, Request-URI , CRLF. SP. CR LF , CRLF.

   Request-Line   = Method SP Request-URI SP HTTP-Version CRLF

, HTTP- GET , HTTP/1.0, . , URL-, :

/checkout/wx_signature?[SIGNATURE REMOVED]Content-Length: 445Connection: closeContent-Type: text/html; charset=iso-8859-1

URL- + %20 . , , . HTTP- , URL-. , " ".


, .

RFC2616 14.13, , Content-Length HTTP 1.1. Connection Content-Type.

, URL?

, . , , , .


HTTP . , , " http://google.com". Google " http://www.google.com".

:

GET / HTTP/1.1
Host: google.com

:

HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Thu, 15 May 2014 21:28:46 GMT
Expires: Sat, 14 Jun 2014 21:28:46 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic

[HTML content removed]

, Google ! :

HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
...
Content-Length: 219

, Content-Type, Content-Length Location. , HTTP , , . , , Location?

- :

HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/Content-Type: text/html; charset=UTF-8Content-Length: 219

Uh-oh... HTTP, , http://www.google.com/Content-Type: text/html; charset=UTF-8Content-Length: 219.


, ... ?

, Apache ( - ).

, " " .

, " " Location: URL-, CRLF ( HTTP, ). , HTTP/1.0 HTTP/1.1, , HTTP/1.0 .

, " " , CRLF.


, , " ", , .

.

+7

, HTTPS-url Django. , HTTPS Apache2, , : SSL django mod_wsgi

+2

Source: https://habr.com/ru/post/1530286/


All Articles