0

I have following url

http://www.example.com/p1/val1/p1/val2

Now I want to pass third parameter as url like '/path/to/file'

http://www.example.com/p1/val1/p1/val2/url/?????

How can I do that with combination of js and php?

After passing above, I would like to get value of url as '/path/to/file'

I am passing above link through js's location.href.

How to do that?

I am getting following error?

Not Found

The requested URL http://www.example.com/p1/val1/p1/val2/url//path/to/file was not found on this server.
Smile
  • 2,770
  • 4
  • 35
  • 57

2 Answers2

0

why didn't use traditional query string?

http://www.example.com?p1[]=val1&p1[]=val2&url=<?php echo urlencode('/path/to/file'); ?>
user5332
  • 758
  • 2
  • 9
  • 17
0

I'm assuming you process your urls this way:

http://www.example.com/p1/val1/p2/val2/...

gets transformed into:

http://www.example.com?p1=val1&p2=val2&...

So, your poblem is that your url parameter receives, as value, either '' or just 'path'.

You could try this, with javascript

var url = 'http://www.example.com/p1/val/p1/val2';
var path = '/path/to/file';
var finalUrl = url + '/url/' + encodeURIComponent(path);
Oscar Paz
  • 18,084
  • 3
  • 27
  • 42