Open Source .htaccess

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

I'm looking for a way to serve both a script and its source without uploading two files. Basically I have a subdomain apps.domain.com which you can run scripts on, but I'm looking to do is handle request to apps.domain.com/src/ differently. Instead of running the files through an interpreter I just want to serve them as raw text files.

Basically Im going to use this rewrite rule.

Code: [ Select ]
RewriteEngine on
RewriteRule ^src/(.*)& /$1 [L]
  1. RewriteEngine on
  2. RewriteRule ^src/(.*)& /$1 [L]

not 100% sure that will work but you get the basic understanding

However, what I want to server anything requested in /src/ to be served as plain text.

Basically I need to through AddHandler default-handler .py in there some for all requests made to /src/.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

I think I may have found how to do this.

Code: [ Select ]
<Directory /src/*>
AddHandler default-handler .py .php
</Directory>

RewriteEngine on
RewriteRule ^src/(.*)$ /$1 [L]
  1. <Directory /src/*>
  2. AddHandler default-handler .py .php
  3. </Directory>
  4. RewriteEngine on
  5. RewriteRule ^src/(.*)$ /$1 [L]


The only question is, will the rewrite cause the directory part to never be true because it always rewrites the url.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

<Directory/> isn't available in htaccess, only server-config and virtual-host. Even then, I believe mod_rewrite is going to move the request out of the context of that handler before it gets a chance to be applied.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

aah, that would explain why I am getting a 500 error when I added the directory part.

I guess I'll change the rewrite to to the following and just have a script print the text to the browser.

Code: [ Select ]
RewriteEngine on
RewriteRule ^src/(.*)$ /src.py/$1 [L]
  1. RewriteEngine on
  2. RewriteRule ^src/(.*)$ /src.py/$1 [L]

PYTHON Code: [ Select ]
 #!/usr/bin/env python
 
import os
 
print("Content-type: text\n")
 
src_file = os.environ['PATH_INFO']
doc_root = os.environ['DOCUMENT_ROOT']
 
try:
    fh = open(doc_root + src_file, "r")
       for line in fh:
           print line,
    except IOError:
       print("I/O Error: Can not open: "),src_file
 
  1.  #!/usr/bin/env python
  2.  
  3. import os
  4.  
  5. print("Content-type: text\n")
  6.  
  7. src_file = os.environ['PATH_INFO']
  8. doc_root = os.environ['DOCUMENT_ROOT']
  9.  
  10. try:
  11.     fh = open(doc_root + src_file, "r")
  12.        for line in fh:
  13.            print line,
  14.     except IOError:
  15.        print("I/O Error: Can not open: "),src_file
  16.  

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 138 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.