Tuckey urlrewritefilter rewrite query string - tuckey-urlrewrite-filter

I am trying to use Tuckey URL rewrite filter to rewrite the query string passed to Solr.
Using the following configuration:
<urlrewrite use-query-strings="true">
<rule>
<from>^/test1/(.*)command=(.*)clean=true(.*)$</from>
<to type="redirect">$1command=$2clean=false$3</to>
</rule>
</urlrewrite>
This configuration works if the query string is not read as a query string i.e.
http://localhost/test1/command=something&clean=true&somethingelese=new
but fails as intended:
http://localhost/test1?command=something&clean=true&somethingelese=new
Any suggestions would be appreciated.
Thank you,

You need to include the question mark in the url.
Here is an example of how I've done it: https://github.com/KevinWorkman/StaticVoidGames/blob/master/StaticVoidGames/src/main/webapp/WEB-INF/urlrewrite.xml
But I think all you really want is something like this:
<urlrewrite use-query-strings="true">
<rule>
<from>^/test1/\?(.*)command=(.*)clean=true(.*)$</from>
<to type="redirect">$1command=$2clean=false$3</to>
</rule>
</urlrewrite>

Related

Exclude directory from Tuckey rewrite filter

I am using tuckey to rewrite URLs:
<rule>
<from>^/?([a-z-/]+)$</from>
<to>/$1.xhtml</to>
</rule>]
However..I have a webservice servlet hosted at:
/ws/service
How do I exclude that from Tuckey rewriting? With the existing rule this will forward the request to /ws/service.xhtml which doesn't exist.
Add the following rule:
<rule>
<from>^/ws/.*$</from>
<to last="true">-</to>
</rule>

How to convert a apache url rewrite rule to IIS rule?

I have url rewrite rule on my .htaccess file like this.
RewriteEngine on
RewriteRule ^(scripts|css)/(.+)\.(.+)\.(js|css)$ $1/$2.$4 [L]
I need to use the same rule on my IIS .
I have used ^(.*)\.[\d]{10}\.(css|js) for the pattern.
I am not sure what to mention Rewrite URL.
I want to rewrite the url /css/structure.1234.css as /css/structure.css
Anyone knows please help?
I read your other ColdFusion question (regarding using regex to add a numerical value to a filename.)
We use an underscore and a 14 digit datestamp. Here's the IIS Rewrite Rule that we use. You can modify it for your needs.
<rule name="CSSJSDatestamp" stopProcessing="true">
<match url="^(.*)(_[0-9]{14}\.)(css|js)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{SCRIPT_NAME}" pattern="/_scripts/" />
</conditions>
<action type="Rewrite" url="{R:1}.{R:3}" />
</rule>
BTW, I don't use this method anymore with my ColdFusion-drive websites since installing IISpeed (PageSpeed for IIS). It automatically minifies, concats and caches JS/CSS files when the files are changed (without the need for cach-busting). It can also optimize images based on device support (ie, reduce size, auto-conversion to WebP, etc). I also really like that it can move all CSS & JSS to the HEAD of the HTML file, prioritize CSS and lazy loads all images "below the fold" with having to add any ColdFusion code or use jQuery.
For more info on IISpeed/Pagespeed, check out:
http://www.iispeed.com/
http://www.iispeed.com/pagespeed/insights
https://developers.google.com/speed/pagespeed/

IIS RewriteUrl RegularExpression

I'm using IIS 7.5 and UrlRewrite Module 2. I've read the official documentation for the module here, as well as many examples on SO and tested my regex on Regexpal. Somehow the translation into the Web.config file is causing me problems. I've tried escaping the parantheses also.
The regex I'm using is:
^partners/(var|distributors|msp|techpartners)/(na|emea|apac)(|/)(.*)
a few example urls:
partners/var/emea
partners/msp/apac/
partners/var/na/abcdabcdabcd
Here is the web.config I have so far:
<rules>
<rule name="partnersListing" enabled="true" stopProcessing="true">
<match url="^partners/(var|distributors|msp|techpartners)/(na|emea|apac)(|/)(.*)" />
<action type="Rewrite" url="partnersList.aspx?type=${R:1}&region={R:2}" />
</rule>
</rules>
Not sure if I want the action to be Rewrite or Redirect yet, but the pattern isn't working either way. Any help is greatly appreciated
Per your answer to my question in the comments:
Is this rule in the site root web.config or a subdirectory web.config?
#Kev in a subdirectory: "/partners"
From the docs:
http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference?amp;clcid=0x409
Quote:
Note that the input URL string passed to a distributed rule is always
relative to the location of the Web.config file where the rule is
defined. For example, if a request is made for
http://www.mysite.com/content/default.aspx?tabid=2&subtabid=3, and a
rewrite rule is defined in the /content directory, then the rule gets
this URL string default.aspx as an input.
Based on this you need to change your url match to:
^(var|distributors|msp|techpartners)/(na|emea|apac)(|/)(.*)
Assuming your re-write rule exists in:
http://example.com/partners/web.config
There is just one other thing which is what appears to be an extraneous $ character in your redirect/rewrite url in front of back reference {R:1}, I'm not sure if you intended that to be there or not.

URL Rewrite requestURI to NVP

I am trying to write a general rule in /WEB-INF/urlrewrite.xml that will take in an arbitrary URI and append the identifiers that follow a root identifier as Name Value Pairs.
For Example:
localhost:8084/URLRewrite/Fruits/Yellow/Banana/banana.jsp
to become
localhost:8084/URLRewrite/Fruits/Yellow/Banana/banana.jsp&key0=Fruits&key1=Yellow&key2=Banana
I know that this will involve regular expressions as well as parameter ambiguity.
Something of similar flavor is like:
<rule>
<from>^/world/([a-z]+)/([a-z]+)$</from>
<to>/world.jsp?country=$1&city=$2</to>
</rule>
Examples:
Input:
nyc
Output:
nyc
Any help or suggestions would be greatly appreciated.
Try this:
<rule>
<from>^/world/([a-z]+)/([a-z]+)$</from>
<to type="redirect">/world.jsp?country=$1&city=$2</to>
</rule>
Maybe you're missing the attribute type with value redirect in your configuration file.

URLrewriteFilter tuckey redirect

I am trying to use UrlRewriteFilter to do a redirect. As we are moving servers and infrastructure all the time to develop our in house cloud solutions we plan to use a lot of this.
My problem is I have a URL like
https:// google.com/web-app/servlet?request-parameters&values
I need to redirect all the URLs which has a value for a particular parameter to a different server.
so a URL like :
https:// google.com/administrator/servlet/ej.processOrder?sec=100&geo=appointment&cus=dubai
If the parameters contain cus=dubai, I need to redirect it to
https://hotmail.com/servlet/ej.processOrder?sec=100&geo=appointment&cus=dubai
I have tried the following but it doesn't seem to work
<urlrewrite use-query-string="true">
<rule match-type="wildcard">
<name>Redirect requests to cases</name>
<description></description>
<from>/administrator/servlet/**?**</from>
<to type="redirect" last="true">http://hotmail.com:8080/servlet/$1?&cus=dubai&$2&$3&amp</to>
</rule>
</urlrewrite>
Thanks for the help.
You will need to make use of the query-string and make sure it matches a particular condition.
From what I can see you would want something like this :
<condition name="query-string" operator="equal">*cus=dubai*</condition>
You will need a rule for each different parameter. One full rule would look like this :
<urlrewrite use-query-string="true">
<rule match-type="wildcard">
<name>Cus = dubai</name>
<from>/administrator/servlet/*</from>
<condition name="query-string" operator="equal">*cus=dubai*</condition>
<to type="redirect" last="true">https://hotmail.com/servlet/ej.processOrder?sec=100&geo=appointment&cus=dubai</to>
</rule>
<!-- other rules go here -->
</urlrewrite>
The condition shall be "type" instead of "name", as:
<condition type="query-string" operator="equal">*cus=dubai*</condition>
Good question and for a situation that I imagine occurs often it is not very well documented in the manual in my opinion.
The following worked for me -
<rule>
<condition type="query-string">foo=123&bar=456</condition>
<from>/index.jsp</from>
<to type="permanent-redirect" last="true">https://somehwere-else.com/blah/blah/</to>
</rule>
So this should work for you -
<rule>
<name>Redirect requests to cases</name>
<condition type="query-string">sec=100&geo=appointment&cus=dubai</condition>
<from>/administrator/servlet</from>
<to type="permanent-redirect" last="true">http://hotmail.com:8080/servlet/sec=100&geo=appointment&cus=dubai</to>
</rule>