0

In implementing clean URLs I wanted to map http://www.pikspeak.com/iframe/3/bird?autoplay=true to http://www.pikspeak.com/iframe.php?id=3&img=bird&autoplay=true using the following regex

RewriteRule ^/iframe/([^/\.]+)/([^/\.?]+)\\?([^/\.]+) /iframe.php?id=$1&img=$2&$3

But the problem is that the last character of the value of img get parameter (in this 'bird') is deleted, i.e. 'bir'. Can you please help out with this issue.

Other than that I am also not able to to get the 'autoplay' parameter in php.

Thanks in advance

rahulg
  • 2,183
  • 3
  • 33
  • 47

1 Answers1

1
  1. I think by \\? you actually mean \?.
  2. No need to escape \. in character classes.
  3. Instead of trying to match the query string, use the [QSA] modifier.
RewriteRule ^/iframe/([^/.]+)/([^/.]+)$ /iframe.php?id=$1&img=$2 [QSA]
Andrew Cheong
  • 29,362
  • 15
  • 90
  • 145
  • 1. No, it is '\\?' , and not '\?' as explained in http://stackoverflow.com/questions/889957/escaping-question-mark-in-regex-javascript 2. Ok, I will try removing \. but am not sure whether it will be effective 3. Will try out [QSA] too. – rahulg May 04 '13 at 06:31
  • 1. No, it's `\?`. It's `\\?` in _that_ question because, as you can see in the very comments, one is for the regex and one is for the _string declaration_, which doesn't apply to `RewriteRule`. So far, you have been matching an optional backslash, which is why the `d` in `bird` was getting backtrack-captured as `$3`, instead of the query string as you expected. More importantly, the query string _is not part of_ `RewriteRule`. – Andrew Cheong May 04 '13 at 06:34
  • using just `\?` had some parsing issues and it would not Rewrite a single line so I used `\\?` which worked to some extent. But `[QSA]` did the job to the end. Thanks. – rahulg May 04 '13 at 07:30
  • 1
    `\\?` only gave the illusion of working because the `?` acted as the "0 or 1" quantifier, and it defaulted to "0". You would've had the same results if you took it out altogether. Anyway, glad it worked out. Happy coding! – Andrew Cheong May 04 '13 at 07:46