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 Answers1

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
Community
  • 1
  • 1
Ross Drew
  • 8,163
  • 2
  • 41
  • 53
  • 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/ –  Oct 30 '15 at 15:00