Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The best solution I've come up with thus far is to have the RewriteMap script return the new url or <code>'__NULL__\n'</code> if no redirect is desired and store this value in a ENV variable. Then, check the ENV variable for <code>!__NULL__</code> and redirect. See <code>.htaccess</code> file below.</p> <p>Also, if anyone is planning on doing something similar to this, inside of the Python script I wrapped a fair amount of it in try/except blocks to prevent the script from dying (in my case, due to failed file/database reads) and subsequent queries being ignored.</p> <h3>/var/www/webroot/.htaccess</h3> <pre><code>RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ - [E=REMAP_RESULT:${remap:$1},NS] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{ENV:REMAP_RESULT} !^__NULL__$ RewriteRule ^(.+)$ /%{ENV:REMAP_RESULT} [R=301,L] </code></pre> <h3>/var/www/remap.py</h3> <pre><code>#!/usr/bin/python import sys def getRedirect(str): try: # to prevent the script from dying on any errors new_url = str # if url needs to be redirected, put this value in new_url # otherwise new_url remains None if new_url == str: new_url = '__NULL__' return new_url except: return '__NULL__' while True: request = sys.stdin.readline().strip() response = getRedirect(request) sys.stdout.write(response + '\n') sys.stdout.flush() </code></pre> <p>Vinko, you definitely helped me figure this one out. If I had more experience with <code>stackoverflow</code>, you would have received <code>^</code> from me. Thank you.</p> <p>I hope this post helps someone dealing with a similar problem in the future.</p> <p>Cheers, Andrew</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload