1

For example i have an URL

http://example.com/myscript/myaction?param1=something

Under myscript alias I have my python cgi script and i want to get the route after myscript as a string. In this case route should be 'myaction'. How to do that with python + pure CGI + apache

1 Answer 1

1

With a regular expression, much like this answer (this question also includes other solutions to the same problem)

import re  

Take your URL

url = 'http://example.com/myscript/myaction?param1=something'

Then extract everything between 'myscript/' and '?'

m = re.search('myscript/(.+?)\?', url)

Then use it

if m:
    found = m.group(1)
    print found
Sign up to request clarification or add additional context in comments.

1 Comment

and how to do it if address either can end with a question or with a new line .../myscript/myaction or even can end with / .../myscript/myaction/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.