Exclude directory from Tuckey rewrite filter - tuckey-urlrewrite-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>

Related

Tuckey urlrewritefilter rewrite query string

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>

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.

Need IIS 7 Url Rewrite Version 1.1 Regex Help To Remove Folder From Url

I am using:
IIS 7
Url Rewrite Module Version 1.1
Asp.Net MVC 4
I am hosting my sites in a shared hosting environment.
No site is hosted in the root folder as all sites are in their own physical folder and I use the domain name of the site as the physical folder name.
I would like to change my urls from this
http://www.mysite1.com/mysite1
http://mysite1.com/mysite1
to this
http://www.mysite1.com/
http://mysite1.com/
I have this and it doesn't work.
**DOES NOT WORK**
<rule name="RemoveFolder" stopProcessing="true">
<match url="mysite1/(.*)" />
<action type="Rewrite" url="/{R:0}" appendQueryString="true" />
</rule>
Can someone give me a regular expression that would add www to any urls and remove the folder that is showing up in the url?
OK. What I typed below, doesn't work for me. I thought it did, but I realized it didn't.
#Cheesemacfly, I'm trying to remove the subfolder from the url,
Redirect the user back to the site with the url MINUS the subfolder,
Make sure that there is NOT a continuous loop.
Cheesemacfly, your answer didn't work, but it did put me on the path to the full correct answer.
Thank you chesse for putting me on the right path.
This rule removes the subfolder from the url and redirects the user back to the page without the subfolder. The condition makes sure that I don't have a continual redirect. Once the url has been rewritten, that conditional will stop the url from matching again.
I placed this rule in the ROOT web.config of my hosting account.
The root ONLY contains a web.config and all of the subfolders.
<rule name="Cleanup" stopProcessing="true">
<match url="theFolderINeedToRemove/(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mywebsite.com/theFolderINeedToRemove$" />
</conditions>
<action type="Redirect" url="/{R:1}" appendQueryString="true" />
</rule>

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>

IIS 7.0 rewrite module for file name

I have a website with many links to *.index.html pages that do not exist any more, all default documents have now changed to index.htm, I'm trying to set a URL redirect/rewrite to the new pages but with no luck, here is an exmaple:
http://example.com/somedirectory/maybeanotherdirectory/index.html
I need to redirect that request to:
http://example.com/somedirectory/maybeanotherdirectory/index.htm
I have added different rules to the web.config but so far I can only redirect to:
http://example.com/index.htm
How do I sustain the exact path while only changing index.html to index.htm?
Such an old question, and I stumbled across it purely by happenstance. In case anybody comes across it in look for an answer, you can install the IIS URL ReWrite module, and add the following to your web.config:
<rewrite>
<rules>
<rule name="Html to htm">
<match url="(.*)\.html" />
<action type="Rewrite" url="{R:1}.htm" />
</rule>
</rules>
</rewrite>
Cheers!