I want to extract the QUERY STRING from HTTP_REFERER and append it to target URL using MOD_REWRITE module in apache configuration file. Could anyone please tell me how to achieve this? Any help will be heartily appreciated.
I don’t know what affect Tomcat may have on things and I’d have to take the time to lookup what 307 signifies. Using 301, however, will force the browser to display the redirection so, if that upsets you, leave it off.
Thank you for your reply. I have got the setting to work with R=307, however the browser displays ugly redirect message. Is there anyway to prevent this?
Your help has been great. Sorry to bother you time and again.
The QSA flag will retain an existing query string but using the mere existence of a query string to prevent a loop won’t help that at all. HOWEVER, in the past, I’ve used a “marker” placed in a query string to prevent looping. Essentially, add a key=value pair such as x=marker when you first redirect and check for x=marker in the query string to prevent looping.
POST? Not really. The POST array is handled differently. The GET array is created by the query string so it can be easily managed.
One more problem I am truck with. Some of the URLs in my site have query strings. I need to append the referer’s query string to the request query string.
With RewriteCond %{QUERY_STRING} ^$, this does not work. And as you have commeded above, removing this condition results into looping. Can you please suggest a way to acheive the foresaid result.
I’m not a TomCat user so I have no experience with its connectors. A quick review of their documentation would indicate, however, that you can configure the connector in any way you see fit. This MAY mean that you can do this but I have no way to verify that it can be done. Sorry.
{Note: Please consider this the answer to the PM, too.}
Could you please help me on one more issue? I am using mod_jk connector. Calls to some of my URLs directly go to tomcat through mod_jk. When this be the case, the RewriteRule is not called and the tomcat handles the request. Is there anyway to configure the Rewrite stuff such that the request is processed before ultimately handled by Tomcat. I tried to search the net but could not find a solution. Thank you in advance.
RewriteEngine on
RewriteCond %{QUERY_STRING} ^$
# check for empty query string - to prevent looping if nothing else
RewriteCond %{HTTP_REFERER} \\?(.*)$
# capture the query string (after the ?)
RewriteRule .? %{REQUEST_URI}?%1 [R=301,L]
# Don't bother to capture the {REQUEST_URI} - you already have it
# %1 is the first atom captured in the associated RewriteCond statements
If you need to learn more about mod_rewrite, may I suggest my signature’s tutorial?