You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Tony VanScoy <tv...@gmail.com> on 2005/08/11 22:28:31 UTC
[users@httpd] mod_rewrite question, escaping quantifiers
I want to redirect certain requests to a pdf depending on a get
variable. nothing new, but I just can't get it to work. So I started
with the basics but just redirecting a certain page to a pdf, which
works.
RewriteRule ^/test\.php$ /pdf/somefile.pdf$ [R,T=application/pdf]
Which works fine. But, since I want to send different pdfs depending
on an ID, I need to handle urls like this one...
/test.php?fileId=12
.. which in turn should redirect to ...
/pdf/pdfnumber12.pdf
... so i wrote this rule...
RewriteRule ^/test\.php\?fileId\=12$ /pdf/pdfnumber12.pdf [R,T=application/pdf]
.. which does not work. But even when I simplify the regex to just ...
RewriteRule ^/test\.php\?$ /pdf/pdfnumber12.pdf [R,T=application/pdf]
..it still doesn't work. So it seems like the question mark cannot be
escaped. I even tried
RewriteRule ^/test\.php[?]$ /pdf/pdfnumber12.pdf [R,T=application/pdf]
.. with no luck. This one works ...
RewriteRule ^/test\.php$ /pdf/pdfnumber12.pdf [R,T=application/pdf]
.. damn question mark. Anyone know what I'm missing? Am I approaching
this in the wrong manner?
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] mod_rewrite question, escaping quantifiers
Posted by John Hicks <jo...@gulfbridge.net>.
Tony VanScoy wrote:
> I got it.
>
> RewriteCond %{QUERY_STRING} ^file\=12$
> RewriteRule ^/test\.php$ /pdf/somfile.pdf [R,L,T=application/pdf]
>
> Looks like i needed regex in the RewriteCond.
>
> Thanks.
That was my bad on the % to $ typo. Sorry.
The last argument for the Rewrite Cond can be either a regex or a quoted
string preceded by a "=" or other operator. You left out the "=". But
what you have is fine.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] mod_rewrite question, escaping quantifiers
Posted by Tony VanScoy <tv...@gmail.com>.
I got it.
RewriteCond %{QUERY_STRING} ^file\=12$
RewriteRule ^/test\.php$ /pdf/somfile.pdf [R,L,T=application/pdf]
Looks like i needed regex in the RewriteCond.
Thanks.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] mod_rewrite question, escaping quantifiers
Posted by Tony VanScoy <tv...@gmail.com>.
>
> RewriteEngine On
> RewriteCond ${QUERY_STRING} "file"
> RewriteRule ^/test\.php$ /index.php [R]
>
Well i fixed my typo ${QUERY_STRING}, it should be %{QUERY_STRING}.
But still not working.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] mod_rewrite question, escaping quantifiers
Posted by Tony VanScoy <tv...@gmail.com>.
> > I want to redirect certain requests to a pdf depending on a get
> > variable. nothing new, but I just can't get it to work. So I started
> > with the basics but just redirecting a certain page to a pdf, which
> > works.
> >
> > RewriteRule ^/test\.php$ /pdf/somefile.pdf$ [R,T=application/pdf]
> >
> > Which works fine. But, since I want to send different pdfs depending
> > on an ID, I need to handle urls like this one...
> >
> > /test.php?fileId=12
> >
> > .. which in turn should redirect to ...
> >
> > /pdf/pdfnumber12.pdf
> >
> > ... so i wrote this rule...
> >
> > RewriteRule ^/test\.php\?fileId\=12$ /pdf/pdfnumber12.pdf [R,T=application/pdf]
> >
> > .. which does not work. But even when I simplify the regex to just ...
> >
> I believe RewriteRule only looks at the URL, not the query string
> following the "?".
>
> But you can use a RewriteCond to look at the query string. Something
> like this ought to work:
>
> RewriteCond ${QUERY_STRING} ="fileId=12"
> ReWriteRule ^/test\.php$ /pdf/somefile.pdf$ [L]
>
> John
That makes sense. I overlooked it in the manual. The only problem is
that it doesn't work. If I set this ...
RewriteEngine On
RewriteCond ${QUERY_STRING} "file"
RewriteRule ^/test\.php$ /index.php [R]
.. and when i call ..
http://www.example.com/test.php?file
.. it doesn't rewrite. But if I remove the RewriteCond and call ...
http://www.example.com/test.php
... it does redirect from /test.php to /index.php. For some reason the
rewrite condition is not matching.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] mod_rewrite question, escaping quantifiers
Posted by John Hicks <jo...@gulfbridge.net>.
Tony VanScoy wrote:
> I want to redirect certain requests to a pdf depending on a get
> variable. nothing new, but I just can't get it to work. So I started
> with the basics but just redirecting a certain page to a pdf, which
> works.
>
> RewriteRule ^/test\.php$ /pdf/somefile.pdf$ [R,T=application/pdf]
>
> Which works fine. But, since I want to send different pdfs depending
> on an ID, I need to handle urls like this one...
>
> /test.php?fileId=12
>
> .. which in turn should redirect to ...
>
> /pdf/pdfnumber12.pdf
>
> ... so i wrote this rule...
>
> RewriteRule ^/test\.php\?fileId\=12$ /pdf/pdfnumber12.pdf [R,T=application/pdf]
>
> .. which does not work. But even when I simplify the regex to just ...
>
I believe RewriteRule only looks at the URL, not the query string
following the "?".
But you can use a RewriteCond to look at the query string. Something
like this ought to work:
RewriteCond ${QUERY_STRING} ="fileId=12"
ReWriteRule ^/test\.php$ /pdf/somefile.pdf$ [L]
John
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org