Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing mod_rewrite to hide the .py extension of a Python script accessed on a web browser
    text
    copied!<p>I want to hide the .py extension of a Python script loaded in a web browser and still have the script run. For example: typing <code>url.dev/basics/pythonscript</code> in the address bar fires pythonscript.py and shows the results in the browser window.</p> <ol> <li>The URL url.dev/basics/pythonscript fetches the static file /pythonscript.py</li> <li>The browser still displays the url url.dev/basics//pythonscript</li> </ol> <p>Typing in <code>url.dev/basics/pythonscript.py</code> DOES work and the Python script results is displayed. I can also get mod_rewrite to rewrite <code>url.dev/basics/phpscript</code> to <code>url.dev/basics/phpscript.php</code> and run the PHP code successfully behind the scenes. </p> <p>But <code>url.dev/basics/pythonscript</code> does NOT redirect to <code>url.dev/basics/pythonscript.py</code> <strong>(I get a 404 Not Found)</strong>.</p> <p><strong>Background Info</strong></p> <p><strong>A)</strong> PHP rewriting works: the following in an .htaccess located in url.dev/basics/ WORKS for PHP scripts: </p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase /basics/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php &lt;/IfModule&gt; </code></pre> <p><strong>B)</strong> Python rewriting does NOT work: the following in an .htaccess located in url.dev/basics/ does NOT work for Python scripts <strong>(I get a 404 Not Found)</strong>:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase /basics/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.py -f RewriteRule ^(.*)$ $1.py &lt;/IfModule&gt; </code></pre> <p><strong>C)</strong> I am a beginning programmer working through <strong>Exercise 2: Your first program</strong> in the <a href="http://philip.greenspun.com/seia/basics" rel="nofollow noreferrer">Basics section of Software Engineering for Internet Applications</a>. I am trying to follow the recommendation to use an execution environment where 'One URL = one file', but want to use Python rather than PHP. <em>I realize that this is not the best way to build a web application down the line. It is only a convention to be used during the initial part of the course linked above.</em></p> <p><strong>D)</strong> I set up the Virtual Hosts development environment in OS 10.6 Snow Leopard so that I can access my development at url.dev as per 'Hacky Holidays' at adactio.com. My Python version is Python 2.6.1.</p> <p><strong>E)</strong> I plan to use Django eventually, but want to work on simpler code first if possible so I can better understand what is going on.</p> <p><strong>F)</strong> I have the following in my httpd.conf: </p> <pre><code> TypesConfig /private/etc/apache2/mime.types AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddHandler cgi-script .py </code></pre> <p>and:</p> <pre><code>LoadModule php5_module libexec/apache2/libphp5.so LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so</code></pre> <p><strong>G)</strong> My Apache version (seen in server log after restarting the server): <em>Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8l DAV/2 PHP/5.3.1 mod_fastcgi/2.4.2 configured -- resuming normal operations</em></p> <p>Looking forward to any help!</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