Apache2 + RewriteMap + Python -- when returning 'NULL', apache hangs -


[solution: see solution below.]

I'm having trouble writing a RewitMap program (using Python) I have a RewriteMap command that points to a Python script that determines whether the requested URL needs to be redirected elsewhere .

When the script ends the output with a linebreak, then the Apache redirect. However, when script output NULL (without linebreak), Apache hang and later HTTP requests are effectively ignored.

The error log does not show any error, the rewrite log succeeds only after a pass after a redirect , then only Pass when NULL is returned by the script, then the request after only pass .

Additionally, stdout with os.fdopen (sys.stdout.fileno (), w ', 0) the buffer length is zero Did not help in determining

Any help would be greatly appreciated. Thank you in advance.

/etc/apache2/httpd.conf

  [...] rewrite log /tmp/apache_rewrite.lock  

/ Etc / apache2 / site-available / default

  & lt; VirtualHost *: 80 & gt; [...] Rewrite engine revival on Revival Ligue Level 1 /var/www/logs/rewrite.log Revival Map Ramp PRG: /var/www/remap.py [...] & lt; / VirtualHost & gt;  

/var/www/webroot/.htaccess

  Revive code on the reverse engine% {REQUEST_FILENAME}! -f rewrite rule (. * _. *) / $ {Remap: $ 1} [R = 301]  

/var/www/remap.py

  #! / Usr / bin / python Import system def GetRedirect (str): new_url = None. If the URL needs to be redirected, then place this value in new_url # otherwise the new_url remains. No return is new_arlan while: request = sys. Stdin.readline () Strip () response = getRedirect (request) If response: sys.stdout.write (feedback + '\ n') Other: sys.stdout.write ('NULL') sys.stdout.flush ()  

You have to return a new line, not 'tap'.

To eliminate Apache, you have to rewrite the URL, waiting for a new line to know if your script does not send a new line, then Apache is waiting forever .

Just replace return ('NULL') back ('zero' n ') , this will redirect to / again if you do this If you do not want to, then there is a program to return to the URL in which you want to have no match in the map.

If you do not want to redirect when there is no match, then I:

RewriteCond% {REQUEST_FILENAME} on RewriteEngine! -f rewrite ($ {remap: $ 1})! NULL RewriteRule (. * _ * *) /% 1 [R = 301]

Use a match in the Rivet condom (with NULL , Will work at all). But given your problem, it looks like the right solution.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -