1

Hi I got a problem with my server. I got 4 inbound links to webpage which look something like this:

myurl.com/default/page.php%3Fid%3D13

they should look like this:

myurl.com/default/page.php?id=13

What would I need to do to achive this? Apache spits out 404 errors when you visit an encoded url link

John
  • 2,015
  • 5
  • 23
  • 37

3 Answers3

0

Have you tried urldecode? It looks like you are getting the URL encoded somehow. If urldecode doesn't do the trick, then you could write a function to decode those particular characters using a map like this.

Revent
  • 2,091
  • 2
  • 18
  • 33
  • How would this be done? Newbie here. In the nginx server config? – John Jan 09 '14 at 01:25
  • it's not the php that's the problem - it's that sites link to a url with "page.php%3Fid%3D13 " which causes 404. it should be "page.php?id=13" – John Jan 09 '14 at 01:27
  • Oh I see. Sorry, I assumed you were getting it in PHP since your question was tagged with PHP. I'm not familiar with nginx, I'll look around. – Revent Jan 09 '14 at 01:28
  • It looks like nginx has its own functions as described [here](http://forum.nginx.org/read.php?29,230121,230123) – Revent Jan 09 '14 at 01:30
  • Also check this [S/O](http://stackoverflow.com/questions/20282054/how-to-urldecode-a-request-uri-string-in-lua) article out. – Revent Jan 09 '14 at 01:32
0

A possible solution (although I wouldn't say it's a good one) is to set up a 404 handler which tries to decode the URL. Maybe you can do some fancy matching to try to guess whether the 404 is due to the URL being encoded.

if(stripos($url, '%3F') !== false){
    header('Location: ' . urldecode($url) );
    exit;
}
Scopey
  • 6,269
  • 1
  • 22
  • 34
0

nginx separates the requested filename from the args, and operates on normalised URIs, therefore, in the location and in the first argument to rewrite, the %3F part can only be matched directly by the ? character (whereas explicit ? from the request will never make it up here), as such:

rewrite     ^/([^?]*)\?(.*)$    /$1?$2?     permanent;

Some more details: https://stackoverflow.com/a/21144014/1122270

Community
  • 1
  • 1
cnst
  • 25,870
  • 6
  • 90
  • 122