[UPHPU] Using mod_rewrite to Pass URLs as GET Variables
Kirk Ouimet
kirk at kirkouimet.com
Sat Apr 18 12:40:57 MDT 2009
Hi list,
I've run into an interesting problem with mod_rewrite. I'm trying to create
a URL structure where I can pass an entire URL as a GET variable. For
example, I want to capture everything past url/:
http://www.mysite.com/url/http://www.google.com/search?hl=en
<http://www.mysite.com/url/http:/www.google.com/search?hl=en&q=test&btnG=Sea
rch&cts=1240079299914> &q=test&btnG=Search&cts=1240079299914
Ideally, I want the GET variable passed to PHP to be:
http://www.google.com/search?hl=en
<http://www.google.com/search?hl=en&q=test&btnG=Search&cts=1240079299914>
&q=test&btnG=Search&cts=1240079299914
I got it working for everything up to the query string using this rule:
RewriteRule ^url/(.+)$ /?page=url&url=$1 [L]
It matched:
http:/www.google.com/search
My guess was anything past the ? would not be interpreted by mod_rewrite, so
I tried to capture the query string by adding a trailing slash to both my
URL and my rewrite rule:
RewriteRule ^url/(.+)/$ /?page=url&url=$1 [L]
This broke things and I got this error:
The requested URL /url/http:/www.google.com/search was not found on this
server.
(Source:
http://www.mysite.com/url/http://www.google.com/search?hl=en&q=test&btnG=Sea
rch&cts=1240079299914/)
I thought I could fix it by encoding the URL contents. I was wrong:
The requested URL
/url/http://www.google.com/search?hl=en&q=test&btnG=Search&cts=1240079299914
/ was not found on this server.
(Source:
http://www.mysite.com/url/http%3A%2F%2Fwww.google.com%2Fsearch%3Fhl%3Den%26q
%3Dtest%26btnG%3DSearch%26cts%3D1240079299914/)
Can anyone give me any insight as to why ^url/(.+)/$ won't match:
http://www.mysite.com/url/http%3A%2F%2Fwww.google.com%2Fsearch%3Fhl%3Den%26q
%3Dtest%26btnG%3DSearch%26cts%3D1240079299914/
Thanks!
Kirk Ouimet
<mailto:kirk at kirkouimet.com> kirk at kirkouimet.com
More information about the UPHPU
mailing list