URL Forwarding based on request parameters - url-rewriting

I am using UrlRewriteFilter from http://www.tuckey.org/urlrewrite/. Mainly I am trying to get the following URL http://domain/application/?param=value to redirect to http://domain/application/?another_param=another_value (simply replacing the request param).
Below are my rule configuration that dosen't seem to work
<rule>
<from>^(.*?param=value)$</from>
<to type="forward">%{context-path}?another_param=another value</to>
</rule>
I have tried several other variations but that didn't seem to work either. any light shed on this issue would be much appreciated

I have been able to resolve the issue using the rule below
<rule>
<name>Selective redirect example redirect</name>
<condition type="parameter" name="param" operator="equal">value</condition>
<to type="forward">?another_param=another_value</to>
</rule>
The key to the answer here is using the conditions rather than depending on the rule to capture the request, in my case I needed only to apply the rule when a certain param value is met. The second part of the answer is removing the <from> tag, and hence all the requests that fulfill the condition will be redirected to the same source page.
Finally, below are the links that were most useful in my search for the answer:
URLRewriteFilter Examples page
The Developer's Tidbits: Tuckey URLRewrite How-To
StackOverflow post: URL Rewrite Filter not working with query parameters containing special characters

Related

Source Urls having '#' in them (anchor links) are not redirecting

I currently have a redirect filter working on an old site with 100+ html pages (static site). However, the remaining API docs (200+ pages) which all have a "#" in them are not redirecting. The original site was implemented as an SPA and hence had anchor links for all API docs; the target site have clean urls.
Snippet of UrlRedirectFilter
<rule>
<name>Delete Transactions</name>
<from>^/api/#create-transaction-deletion$</from>
<to last="true" type="redirect">https://baseurl/apis/Transaction/deleteTransactions</to>
<rule>
<name>Payment Charge</name>
<from>^/api/#paymentcharge$</from>
<to last="true" type="redirect">https://baseurl/apis/Payment%20Method/PaymentMethodCharge/</to>
Is there a hidden rule in url tuckey filter that discards anchor links? Is there a regex I need to be aware of? If none of the regex patterns work on the filter, what's the best way to move forward by extending urlrewriteFilter? Thanks!

outboundRule for dynamically generated content using the IIS Rewrite module

I am trying to write the outbound rules for URLs using the IIS Rewrite module. It is working fine for the static URLs, however, the outbound rule is not applying on the dynamically generaged URLs using the script. In some places in the application, the anchor tags with href () are generating using the jQuery script. The outbound rules are not applying on these type of URLs.
I am using the below pre condition to include the script files, still not working.
<preCondition name="ResponseIsTextAnything">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)" />
</preCondition>
Appreciate your expertise suggestions here. Thank you.

Is their an equivalent of a Java servlet in Classic ASP or how would I simulate one?

I'm assigned the task of implementing session checking for a Classic ASP application. I don't want to include session checking on every single page.
I'd rather use something that's akin to a servlet or servlet filter in Java. The problem is I don't know of any implementation in Classic ASP which approximates this effect. Must I check for an existing session in each and every page or is there something I can do on an application-wide level which will check the request?
I was thinking of creating a URL rewrite rule which forwards every request to a page which checks the session and either redirect if there is no session or forwards the user to the requested URL if a session exists. Any ideas or thoughts would be appreciated.
Thank you.
You can use IIS rewrite rules for this purpose.
Create a simple rewrite rule like this:
<rule name="Rewrite html">
<match url="/(.*)\.html$" />
<action type="Rewrite" url="{R:1}.asp" />
</rule>
You'll have to consider the directory structure, you are using. Then decide where to put the web.config rules and adjust above rule accordingly.

URL Re-Writing in Umbraco - Page Moved Under New Directory

I'm looking to use the URLRewriting.config within Umbraco to set up some redirects. The majority of them are working fine, but a few are causing headaches.
I have a page: /testpage.aspx which on the new site is now under /directory/testpage.aspx. I've tried a couple of rules, but they either fall into a loop, or just send me to the first page - which obviously gives a 404 error.
As far as I can tell, the rule below should satisfy this rewrite and work, but instead I'm just getting the original page - which is a 404 on this site.
<add name="Redirect400" rewriteUrlParameter="ExcludeFromClientQueryString" redirect="Domain" ignoreCase="true"
virtualUrl="^~/testpage.aspx$"
destinationUrl="/directory/testpage.aspx"
redirectMode="Permanent" />
Those regular expressions (please correct me if I'm wrong), should be saying that any page that starts and ends with /testpage.aspx is redirected to the new URL? Can anyone offer any assistance on this?
there is bit change in your virtual URL because that only gets which has www.domain.com/testpage.aspx
It will not get following results:
www.domain.com/abc/testpage.aspx
www.domain.com/abc/main/testpage.aspx
www.domain.com/abc/main/test/testpage.aspx
Please try following, I haven't tested it but I am guessing it is that.
<add name="Redirect400" rewriteUrlParameter="ExcludeFromClientQueryString" redirect="Domain" ignoreCase="true"
virtualUrl="^~(.*)/testpage.aspx$"
destinationUrl="/directory/testpage.aspx"
redirectMode="Permanent" />
let me know if you need more help
thanks

Using URL Rewrite 2.0 in IIS7 and cleaning POSTs

I'm having some issues with setting up rules in URL Rewrite 2.0 using IIS 7. I'm working on a website that is a combination of more modern .NET 4.0 stuff all the way back to classic .ASP stuff. My current task is to try and strip some specific characters out of user input to help prevent against XSS attacks.
I get the basic syntax:
<rule name="Rule Name" stopProcessing="true">
<match url="myPage.asp" />
<conditions>
<add input="" pattern="" />
</conditions>
<action type="" />
</rule>
I know I need three steps,
1) Ensure that what we're looking at is a post
2) Identify any of a number of bad characters using regex
3) Continue the post with those characters stripped out.
The first I believe can be addressed by this:
<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" />
What is frustrating me is the second and third issue.
The second is also an input, but I'm stuck trying to find the best {} variable to put in the input. Right now I have this:
<add input="{REQUEST_URI}" pattern="[\\\|<>]" />
but I know that {REQUEST_URI} is not the right variable to go there. I've been on the URL rewrite site (http://www.iis.net/download/urlrewrite), and I've found the IIS 6.0 list of server variables (http://msdn.microsoft.com/en-us/library/ms524602(v=vs.90).aspx), but I can't seem to find a good list of the variables available to me in 7.0 and above and what they mean. Is this something anyone has bookmarked somewhere and can pass along?
The third is also giving me issues. Right now, on some other rules, I have <action type="AbortRequest" /> set, but for this, I'm not looking to stop the request, I'm looking to just remove the bad characters and continue the POST. The custom rule setup in IIS looks promising, but it just seems to want to redirect to a URL, not do anything else. Is this something that's even possible?
I should also note that I'm looking into an IIS Managed Module as an alternative to get what I'm looking for. Does that sound like a better avenue to anyone?
So, turns out that you can't do it and that I was misinterpreting the scope of the URL rewrite application. I should be looking at an IIS Managed Module, and will pivot to that in the future.

Resources