Hello, i want to pass variables in url with slashes for example if the url is http://host.com/script/2008/05/05
the script would get 2008, 05 and 05 as variables (year,month,day)
i'm using mod_python/publisher.
Thanks in advance

If the script has access to the URL you could do something like:

>>> url_in = 'http://host.com/script/2008/05/05'
>>> match_text = 'script/'
>>> index = url_in.find(match_text) + len(match_text)
>>> url_in[index:].split('/')
['2008', '05', '05']
>>>

Is that kind of what you were looking for?

Thanks for the replies but I get forbidden page everytime when i try to go to my address with additional variables in slashes. I assume there should be some .htaccess setting for the server to be able to divide the url into the "actual url" and the variables.
More of a server issue i suppose, any1 had experience with this? :)

Thanks for the replies but I get forbidden page everytime when i try to go to my address with additional variables in slashes. I assume there should be some .htaccess setting for the server to be able to divide the url into the "actual url" and the variables.
More of a server issue i suppose, any1 had experience with this? :)

Post the relevant code and print, then post also, the URL you are trying to use. You can insert the slash, if that is what you are trying to do, the same way you insert any other character or string.

slash = "/"
mm = 5
dd = 17
ccyy = 2009
URL = "http:%s%swww.google.com%s%02d%s%02d%s%d%s" % \
       (slash, slash, slash, mm, slash, dd, slash, ccyy, slash)
print URL

Thanks for the replies but I get forbidden page everytime when i try to go to my address with additional variables in slashes. I assume there should be some .htaccess setting for the server to be able to divide the url into the "actual url" and the variables.
More of a server issue i suppose, any1 had experience with this? :)

Let me get this straight... you're trying to access this page: http://host.com/script , and pass these as variables: 2008/05/05 ??

I guess my question to you is: why? I'm certainly not an expert on the subject, but I'm pretty sure it will never work like that... why don't you just use POST/GET or some other similar manner to pass your variables? If you need help on passing variables in HTML just google "HTML pass variable" and you'll get plenty of answers.

As Scru said, if you're trying to pass the values as a GET, you need to URLencode the string containing the date. If you feel some overwhelming need to do this manually, the URL encoding for a forward slash is '%2F'. Thus, it would look like this:

http://www.host.com/script?%2F2008%2F05%2F05

Note the question mark (?) after the name of the script, rather than another slash. This indicates that the string following it should be treated as a GET parameter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.