I need a piece of code that basically does task of matching URL. I have listed 2 scenarios below to clear how I need the things.
Match URL may/may not contain sub-directory, so there are 2 scenarios.
http://example.com/?pgid=1
http://example.com/?pgid=1&opt2=2
http://example.com/?opt2=2&pgid=1
http://example.com/?pgid=1&opt2=2&opt3=3
http://example.com/?opt2=2&pgid=1&opt3=3
http://example.com/?opt2=2&opt3=3&pgid=1
should match => http://example.com/?pgid=1
and
http://example.com/sub-dir/?pgid=1
http://example.com/sub-dir/?pgid=1&opt2=2
http://example.com/sub-dir/?opt2=2&pgid=1
http://example.com/sub-dir/?pgid=1&opt2=2&opt3=3
http://example.com/sub-dir/?opt2=2&pgid=1&opt3=3
http://example.com/sub-dir/?opt2=2&opt3=3&pgid=1
should match => http://example.com/sub-dir/?pgid=1
How can I achieve above thing, help appreciated. Thanks.
The regex to mach that url is:
\?pgid=1$As i understand you don’t want any other query string parameters in your url.