I use mod_rewrite to rewrite beautiful URLs into a form supported by Spring 2.5.
e.g. /category/cat1?q=x => /controller?category=cat1&q=x
However, from my controller I want to know the source URL from which the request came (so I can create a link if necessary). This approach is necessary in the general case for all pages, so it is difficult to hard code.
How can I access the source line of the path + request from my controller?
I tried using $ 0 to include the full path, but this does not include the query string. I canโt just add the path and query string, as this will add some parts of the path as parameters. /category/cat1?category=cat1&q=xPay attention to adding an unwanted parameter &category=cat1, this leads to the fact that the URL no longer matches the one specified from the browser.
I hope that mod_rewrite will allow me to refer to the full URL and encode it as a parameter, so that my rule looks like this:
RewriteRule /category/(.+)
/controller?category=$1&_originalUrl=${escape:$0}?${escape:<original query string>}
[QSA]
Using my original example, the final result passed to my controller will look like this:
/controller?category=cat1&_originalUrl=%2Fcategory%2Fcat1%3Fsearch%3Dx&search=x
The important part is the value &_originalUrlthat should be %2Fcategory%2Fcat1%3Fsearch%3Dx, which is in its unexpressed version /category/cat1?q=x(the source URL of the request sent from the browser).
, !