Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3221398
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:52:17+00:00 2026-05-17T15:52:17+00:00

I want to hide the .py extension of a Python script loaded in a

  • 0

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 url.dev/basics/pythonscript in the address bar fires pythonscript.py and shows the results in the browser window.

  1. The URL url.dev/basics/pythonscript fetches the static file /pythonscript.py
  2. The browser still displays the url url.dev/basics//pythonscript

Typing in url.dev/basics/pythonscript.py DOES work and the Python script results is displayed. I can also get mod_rewrite to rewrite url.dev/basics/phpscript to url.dev/basics/phpscript.php and run the PHP code successfully behind the scenes.

But url.dev/basics/pythonscript does NOT redirect to url.dev/basics/pythonscript.py (I get a 404 Not Found).

Background Info

A) PHP rewriting works: the following in an .htaccess located in url.dev/basics/ WORKS for PHP scripts:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /basics/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>

B) Python rewriting does NOT work: the following in an .htaccess located in url.dev/basics/ does NOT work for Python scripts (I get a 404 Not Found):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /basics/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.py -f
RewriteRule ^(.*)$ $1.py
</IfModule>

C) I am a beginning programmer working through Exercise 2: Your first program in the Basics section of Software Engineering for Internet Applications. 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. 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.

D) 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.

E) 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.

F) I have the following in my httpd.conf:


TypesConfig /private/etc/apache2/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddHandler cgi-script .py

and:

LoadModule php5_module        libexec/apache2/libphp5.so
LoadModule fastcgi_module     libexec/apache2/mod_fastcgi.so

G) My Apache version (seen in server log after restarting the server): 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

Looking forward to any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:52:18+00:00Added an answer on May 17, 2026 at 3:52 pm

    I found the solution: I needed to add the application MIME type so that the Apache Web Server understands it should run the code.

    In url.dev/basics/.htaccess add:

    <IfModule mime_module>
    AddType application/x-httpd-py .py
    </IfModule>
    

    Don’t forget to restart Apache: sudo apachectl graceful

    And it works! http://url.dev/basics/pythonscript runs the code in pythonscript.py! Note that I’m not sure if this is the best way to do it, but it works.

    Here is my complete .htaccess file:

    # Options +ExecCGI
    # SetHandler cgi-script
    
    <IfModule mime_module>
    AddType application/x-httpd-py .py
    </IfModule>
    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /basics/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.py -f
    RewriteRule ^(.*)$ $1.py
    </IfModule>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im developing a web application(J2EE,Struts2,JSP,Tomcat) I want to hide the .jsp extension from webpages.
i tried this code to hide the php file extension i have this url
i have an element in my page. <div id=element>try</div> I want hide it when
I want to hide public methods from the IntelliSense member list. I have created
I have a small number of static sites where I simply want to hide
I want to hide scrollbar to appear on a long div,but still able to
I have a website in PHP, and I'm trying to hide the extension. I've
I want to hide file extensions from a URL like if the current URL
have this code in a htaccess file to hide the final php extension of
I have a url that is easily accessible when you request it as: http://example.com/2005/01/example.html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.