You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "Bhattacharya, Sudip" <su...@genpact.com> on 2012/10/04 17:03:27 UTC

[users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?

Hi,

I am trying to configure caching for a website using apache proxy.

Some of the URLs are using a random parameter in the URL to avoid caching.

The URL would look like this:
http://foo.com/folder/xmlfiles/static.xml?rand= 0.36176968908944995

The xml files are static files, but the application attaches a random number at the end to disable caching. I need to remove the rand parameter to enable caching, without modifying the original application.

There would be other URLs which would have valid query strings, so I need to limit the rewrite operation to the specific xmlfiles folder urls.

Some of the examples on internet seems to be removing the query string from all requests.

Regards,
Sudip Kumar Bhattacharya
This e-mail (and any attachments), is confidential and may be privileged. It may be read, copied and used only
by intended recipients. Unauthorized access to this e-mail (or attachments) and disclosure or copying of its 
contents or any action taken in reliance on it is unlawful. Unintended recipients must notify the sender immediately 
by e-mail/phone & delete it from their system without making any copies or disclosing it to a third person.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?

Posted by "Bhattacharya, Sudip" <su...@genpact.com>.
[PT,L] is not allowing caching. Seems like mod_cache treats it as a dynamic file, because of the query string.
I may have to live with the redirection option [R=301,L] unless there are some other alternatives that I can try out. At least mod_cache is able to cache the redirected url as it does not have a query string anymore. But there is round trip involved from the browser.

To Nick's question, the links are coming in the body of a JSP file, where a javascript is loading these XML files for some processing at browser end. I can give mod_substitute a try do modify the JSP output to tamper these links, but it would involve looking at the contents of each request searching for this pattern. It might cause a negative impact on performance.
I have no idea of ProxyHTMLURLMap, so not sure how to try that option. 

-----Original Message-----
From: Ben Johnson [mailto:ben@indietorrent.org] 
Sent: Thursday, October 04, 2012 11:27 PM
To: users@httpd.apache.org
Subject: Re: [users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?



On 10/4/2012 12:01 PM, Bhattacharya, Sudip wrote:
> Great. This one worked.
> 
> However, it looks like the first request with the query string returns a 301 moved permanently response, requiring another request from the browser to the file without the query string.
> 
> Can this redirection be avoided, so that the server returns the cached file on the original response only?

Just change the last line to the following (to use Pass-Through, instead of Redirecting with a specific status code):

RewriteRule ^(.*)$ %{REQUEST_URI}? [PT,L]

P.S. I can't speak to Nick Kew's comments (I don't use mod_cache), so you'll just have to test this and see if it works for your purposes.

Good luck,

-Ben

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

This e-mail (and any attachments), is confidential and may be privileged. It may be read, copied and used only
by intended recipients. Unauthorized access to this e-mail (or attachments) and disclosure or copying of its 
contents or any action taken in reliance on it is unlawful. Unintended recipients must notify the sender immediately 
by e-mail/phone & delete it from their system without making any copies or disclosing it to a third person.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?

Posted by Ben Johnson <be...@indietorrent.org>.

On 10/4/2012 12:01 PM, Bhattacharya, Sudip wrote:
> Great. This one worked.
> 
> However, it looks like the first request with the query string returns a 301 moved permanently response, requiring another request from the browser to the file without the query string.
> 
> Can this redirection be avoided, so that the server returns the cached file on the original response only?

Just change the last line to the following (to use Pass-Through, instead
of Redirecting with a specific status code):

RewriteRule ^(.*)$ %{REQUEST_URI}? [PT,L]

P.S. I can't speak to Nick Kew's comments (I don't use mod_cache), so
you'll just have to test this and see if it works for your purposes.

Good luck,

-Ben

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?

Posted by "Bhattacharya, Sudip" <su...@genpact.com>.
Great. This one worked.

However, it looks like the first request with the query string returns a 301 moved permanently response, requiring another request from the browser to the file without the query string.

Can this redirection be avoided, so that the server returns the cached file on the original response only?



-----Original Message-----
From: Ben Johnson [mailto:ben@indietorrent.org] 
Sent: Thursday, October 04, 2012 9:23 PM
To: users@httpd.apache.org
Subject: Re: [users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?



On 10/4/2012 11:32 AM, Bhattacharya, Sudip wrote:
> Hi Sridhar,
> 
> This would apply to the whole virtual host. I need to enable it for specific subfolders.

Something like this should work:

RewriteCond %{REQUEST_URI} =/folder/xmlfiles/static.xml RewriteCond %{QUERY_STRING} !=""
#The ? at the end causes the %{QUERY_STRING} to be omitted #from %{REQUEST_URI} during rewriting.
RewriteRule ^(.*)$ %{REQUEST_URI}? [R=301,L]

If any mod_rewrite expert has suggestions or revisions, please jump in.

> -----Original Message-----
> From: sridhar basam [mailto:sridhar.basam@gmail.com]
> Sent: Thursday, October 04, 2012 9:00 PM
> To: users@httpd.apache.org
> Subject: Re: [users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?
> 
> On Thu, Oct 4, 2012 at 11:03 AM, Bhattacharya, Sudip <su...@genpact.com> wrote:
>> Hi,
>>
>> I am trying to configure caching for a website using apache proxy.
>>
>> Some of the URLs are using a random parameter in the URL to avoid caching.
>>
>> The URL would look like this:
>> http://foo.com/folder/xmlfiles/static.xml?rand= 0.36176968908944995
>>
>> The xml files are static files, but the application attaches a random number at the end to disable caching. I need to remove the rand parameter to enable caching, without modifying the original application.
>>
>> There would be other URLs which would have valid query strings, so I need to limit the rewrite operation to the specific xmlfiles folder urls.
>>
>> Some of the examples on internet seems to be removing the query string from all requests.
> 
> The module already supports it for you, you need to just enable it.
> 
> http://httpd.apache.org/docs/2.4/mod/mod_cache.html#cacheignorequeryst
> ring
> 
> 
> Sridhar
> 
> 
> 
>>
>> Regards,
>> Sudip Kumar Bhattacharya

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

This e-mail (and any attachments), is confidential and may be privileged. It may be read, copied and used only
by intended recipients. Unauthorized access to this e-mail (or attachments) and disclosure or copying of its 
contents or any action taken in reliance on it is unlawful. Unintended recipients must notify the sender immediately 
by e-mail/phone & delete it from their system without making any copies or disclosing it to a third person.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?

Posted by Nick Kew <ni...@webthing.com>.
On 4 Oct 2012, at 16:52, Ben Johnson wrote:

> 
> 
> On 10/4/2012 11:32 AM, Bhattacharya, Sudip wrote:
>> Hi Sridhar,
>> 
>> This would apply to the whole virtual host. I need to enable it for specific subfolders.
> 
> Something like this should work:
> 
> RewriteCond %{REQUEST_URI} =/folder/xmlfiles/static.xml
> RewriteCond %{QUERY_STRING} !=""
> #The ? at the end causes the %{QUERY_STRING} to be omitted
> #from %{REQUEST_URI} during rewriting.
> RewriteRule ^(.*)$ %{REQUEST_URI}? [R=301,L]
> 
> If any mod_rewrite expert has suggestions or revisions, please jump in.

OTTOMH I doubt that would work.  The rewrite would come too late to
stop mod_cache seeing and acting on the query string.  But I could
be wrong.

The ideal solution would be to strip off those query strings before they
ever reach the browser (which also helps the browser itself to cache things).
Are they generated as links or as HTTP redirects?  If links then a
ProxyHTMLURLMap (if the performance hit of parsing HTML is acceptable);
if HTTP headers then a ProxyPassReverse variant would seem a startingpoint.

-- 
Nick Kew
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?

Posted by Ben Johnson <be...@indietorrent.org>.

On 10/4/2012 11:32 AM, Bhattacharya, Sudip wrote:
> Hi Sridhar,
> 
> This would apply to the whole virtual host. I need to enable it for specific subfolders.

Something like this should work:

RewriteCond %{REQUEST_URI} =/folder/xmlfiles/static.xml
RewriteCond %{QUERY_STRING} !=""
#The ? at the end causes the %{QUERY_STRING} to be omitted
#from %{REQUEST_URI} during rewriting.
RewriteRule ^(.*)$ %{REQUEST_URI}? [R=301,L]

If any mod_rewrite expert has suggestions or revisions, please jump in.

> -----Original Message-----
> From: sridhar basam [mailto:sridhar.basam@gmail.com] 
> Sent: Thursday, October 04, 2012 9:00 PM
> To: users@httpd.apache.org
> Subject: Re: [users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?
> 
> On Thu, Oct 4, 2012 at 11:03 AM, Bhattacharya, Sudip <su...@genpact.com> wrote:
>> Hi,
>>
>> I am trying to configure caching for a website using apache proxy.
>>
>> Some of the URLs are using a random parameter in the URL to avoid caching.
>>
>> The URL would look like this:
>> http://foo.com/folder/xmlfiles/static.xml?rand= 0.36176968908944995
>>
>> The xml files are static files, but the application attaches a random number at the end to disable caching. I need to remove the rand parameter to enable caching, without modifying the original application.
>>
>> There would be other URLs which would have valid query strings, so I need to limit the rewrite operation to the specific xmlfiles folder urls.
>>
>> Some of the examples on internet seems to be removing the query string from all requests.
> 
> The module already supports it for you, you need to just enable it.
> 
> http://httpd.apache.org/docs/2.4/mod/mod_cache.html#cacheignorequerystring
> 
> 
> Sridhar
> 
> 
> 
>>
>> Regards,
>> Sudip Kumar Bhattacharya

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?

Posted by "Bhattacharya, Sudip" <su...@genpact.com>.
Hi Sridhar,

This would apply to the whole virtual host. I need to enable it for specific subfolders.

-----Original Message-----
From: sridhar basam [mailto:sridhar.basam@gmail.com] 
Sent: Thursday, October 04, 2012 9:00 PM
To: users@httpd.apache.org
Subject: Re: [users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?

On Thu, Oct 4, 2012 at 11:03 AM, Bhattacharya, Sudip <su...@genpact.com> wrote:
> Hi,
>
> I am trying to configure caching for a website using apache proxy.
>
> Some of the URLs are using a random parameter in the URL to avoid caching.
>
> The URL would look like this:
> http://foo.com/folder/xmlfiles/static.xml?rand= 0.36176968908944995
>
> The xml files are static files, but the application attaches a random number at the end to disable caching. I need to remove the rand parameter to enable caching, without modifying the original application.
>
> There would be other URLs which would have valid query strings, so I need to limit the rewrite operation to the specific xmlfiles folder urls.
>
> Some of the examples on internet seems to be removing the query string from all requests.

The module already supports it for you, you need to just enable it.

http://httpd.apache.org/docs/2.4/mod/mod_cache.html#cacheignorequerystring


Sridhar



>
> Regards,
> Sudip Kumar Bhattacharya
> This e-mail (and any attachments), is confidential and may be 
> privileged. It may be read, copied and used only by intended 
> recipients. Unauthorized access to this e-mail (or attachments) and 
> disclosure or copying of its contents or any action taken in reliance on it is unlawful. Unintended recipients must notify the sender immediately by e-mail/phone & delete it from their system without making any copies or disclosing it to a third person.

>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

This e-mail (and any attachments), is confidential and may be privileged. It may be read, copied and used only
by intended recipients. Unauthorized access to this e-mail (or attachments) and disclosure or copying of its 
contents or any action taken in reliance on it is unlawful. Unintended recipients must notify the sender immediately 
by e-mail/phone & delete it from their system without making any copies or disclosing it to a third person.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to strip out the query parameter for specific URLs using mod_rewrite?

Posted by sridhar basam <sr...@gmail.com>.
On Thu, Oct 4, 2012 at 11:03 AM, Bhattacharya, Sudip
<su...@genpact.com> wrote:
> Hi,
>
> I am trying to configure caching for a website using apache proxy.
>
> Some of the URLs are using a random parameter in the URL to avoid caching.
>
> The URL would look like this:
> http://foo.com/folder/xmlfiles/static.xml?rand= 0.36176968908944995
>
> The xml files are static files, but the application attaches a random number at the end to disable caching. I need to remove the rand parameter to enable caching, without modifying the original application.
>
> There would be other URLs which would have valid query strings, so I need to limit the rewrite operation to the specific xmlfiles folder urls.
>
> Some of the examples on internet seems to be removing the query string from all requests.

The module already supports it for you, you need to just enable it.

http://httpd.apache.org/docs/2.4/mod/mod_cache.html#cacheignorequerystring


Sridhar



>
> Regards,
> Sudip Kumar Bhattacharya
> This e-mail (and any attachments), is confidential and may be privileged. It may be read, copied and used only
> by intended recipients. Unauthorized access to this e-mail (or attachments) and disclosure or copying of its
> contents or any action taken in reliance on it is unlawful. Unintended recipients must notify the sender immediately
> by e-mail/phone & delete it from their system without making any copies or disclosing it to a third person.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org