Coder Social home page Coder Social logo

jooooooon / apache-rewrite-maps-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lagrangianpoint/apache-rewrite-maps-python

0.0 1.0 0.0 3 KB

A set of rewrite maps for Apache written in Python to extend the functionality of mod_rewrite and/or .htaccess files.

Python 100.00%

apache-rewrite-maps-python's Introduction

Apache Rewrite Maps (Python)

A set of rewrite maps for Apache written in Python to extend the functionality of mod_rewrite and/or .htaccess files. You'll be able to convert underscores to spaces, underscores to hyphens, or spaces to hyphens.

Requirements

  • Python 2.7
  • Apache with mod_rewrite enabled

Installation

  1. Download under2space.py, under2hyphen.py , and/or space2hyphen.py to a segure directory (one that is only accessible to apache) ,

  2. Give execution permissions to these scripts with:

    cd /path/to/secure/directory/
    sudo chmod +x *.py
    
  3. Add the following RewriteMap conditions to your Virtual Host file. You can use the following as an example:

    <VirtualHost *:80>
    	RewriteEngine On
    	
    	RewriteMap under2space prg:/path/to/under2space.py
    	RewriteMap under2hyphen prg:/path/to/under2hyphen.py
    	RewriteMap space2hyphen	prg:/path/to/space2hyphen.py
       
    	# Sample usage
    	RewriteRule ^(.*).php $ /blog/${under2space:$1} [L,R=301]    
    	RewriteRule ^(.*).py $ /articles/${under2hyphen:$1} [L,R=301]    
    	RewriteRule ^(.*).asp $ /api/${space2hyphen:$1} [L,R=301]    
    </VirtualHost>
    
  4. Restart Apache.

Notes

It is very importat to keep in mind that these scripts will be loaded only once by Apache, and they will keep running all the time. So if you plan to modify any of this scripts live , you'll need to restart apache every time. For debugging purposes, I strongly recommend you adding the following to your virtual host:

        RewriteEngine On
        RewriteLogLevel 9
        RewriteLog /var/log/apache2/rewrite.log

apache-rewrite-maps-python's People

Contributors

lagrangianpoint avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.