ImageResizer web.config rewrite rule not working properly - iis-7

I am using ImageResizer to read images from my Amazon S3, with this rule it is working great:
<rewrite>
<rules>
<rule name="Rewrite to s3" stopProcessing="true">
<match url="^(.*)/(productimages)/(.*)" />
<action type="Rewrite" url="{R:1}/mybucketname/{R:3}" appendQueryString="true" redirectType="Found" />
</rule>
</rules>
</rewrite>
For this URL:
http://localhost:7514/s3/productimages/112/0718877-21_lg.jpg
Loads this image form Amazon S3:
http://localhost:7514/s3/mybucketname/112/0718877-21_lg.jpg
Everything is working BUT I need to get rid of the /s3 in the first URL, so it would be:
http://localhost:7514/productimages/112/0718877-21_lg.jpg
I have tried a million different combinations and I cannot get it.

Without knowing what you've tried, it's a bit difficult to help.
Have you tried something like this?
<rewrite>
<rules>
<rule name="Rewrite to s3" stopProcessing="true">
<match url="^productimages/(.*)" />
<action type="Rewrite" url="s3/mybucketname/{R:1}" appendQueryString="true" redirectType="Found" />
</rule>
</rules>
</rewrite>

Related

IIS Web.config Redirect with query to subdomain

I am looking to make a redirect on URLs with a specific search query to go to a sub domain like below:
Original:
https://example.com/property.php?id=9999
New:
https://search.example.com/property/9999
I tried this (second rule):
<rewrite>
<rules>
<rule name="Sitemap Re-direct" enabled="true" stopProcessing="true">
<match url="sitemap.xml" />
<action type="Rewrite" url="sitemap" appendQueryString="false"/>
</rule>
<rule name="RewriteToSearch">
<match url="^search/property.php?id=([0-9]+)" />
<action type="Rewrite" url="https://search.sourced.co/property/{R:1}/" />
</rule>
</rules>
</rewrite>
But it did not work?
Thanks!

iis rewrite keep path (keep everything but the file name)

attempting to re route
https://xxxxx.aaa.bb.cc.dd/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O
and
https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main_Rewrite.aspx?FOB=O
and
https://xxxxx.aaa.bb.cc.dd/net/prodmirror/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/net/prodmirror/FOB_Main_Rewrite.aspx?FOB=O
so retain everything before an aspx page and the query string. and replace it with a new aspx page. (replace only the filename and keep everything else)
here is my attempt.
<rule name="Fob_Main_decommisioned" stopProcessing="true">
<match url="^fob_main.aspx" />
<action type="Redirect" url="/FOB_Main_Rewrite.aspx" redirectType="Temporary" />
</rule>
this is working fine for
https://xxxxx.aaa.bb.cc.dd/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O
but it is changing.
https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O
I also attempted
<rule name="Fob_Main_decommisioned" stopProcessing="true">
<match url="^fob_main.aspx" />
<action type="Redirect" url="{HTTP_HOST}/FOB_Main_Rewrite.aspx" redirectType="Temporary" />
</rule>
but now I am getting
https://xxxxx.aaa.bb.cc.dd/testdev/xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O
I also attempted
<rule name="Fob_Main_decommisioned" stopProcessing="true">
<match url="(^.*)fob_main.aspx" />
<action type="Redirect" url="/{R:1}FOB_Main_Rewrite.aspx" redirectType="Temporary" />
</rule>
but I am back to
https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O
(it is removing the testdev again)
interestingly using this rule
<rule name="Fob_Main_decommisioned" stopProcessing="true">
<match url="(^.*)fob_main.aspx" />
<action type="Redirect" url="/{R:1}FOB_Main_Rewrite.aspx" redirectType="Temporary" />
and directly typing into the browser
https://xxxxx.aaa.bb.cc.dd/testdev/testdev/FOB_Main.aspx?FOB=O
re routes me to the page I would like to go to.
https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main_Rewrite.aspx?FOB=O
This rule looks correct (if you placed this rule in root application):
<rule name="Fob_Main_decommisioned" stopProcessing="true">
<match url="(^.*)fob_main.aspx" />
<action type="Redirect" url="/{R:1}FOB_Main_Rewrite.aspx" redirectType="Temporary" />
</rule>
This rule will work, if you placed it in sub application:
<rule name="Fob_Main_decommisioned" stopProcessing="true">
<match url="^fob_main.aspx" />
<action type="Redirect" url="FOB_Main_Rewrite.aspx" redirectType="Temporary" />
</rule>
Most probably you back to https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O, because browser cached your wrong redirect before. Can you please do this steps:
Apply this rule
Clear cache in your browser
Try to open https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main.aspx?FOB=O

web.config Redirect Rule - Match URL

This seems to be a pretty straight forward change, however it's not matching the URL and none of the answers on stackoverflow seem to address this simple use of redirect rules. I believe it has something to do with the '?id=XXXX' portion of the URL.
We have some old versions of pages, which I am trying to add redirects to the new version of the pages.
Here's an example of my rules:
<rule name="old_Page" stopProcessing="true">
<match url="^Page.aspx?id=12345"/>
<action type="Redirect" url="http://www.example.com/newPage.aspx" redirectType="Permanent" />
</rule>
Any help would be most appreciated.
I used a different method to create Static Redirects in the web.config from this article:
https://www.iis.net/learn/extensions/url-rewrite-module/using-rewrite-maps-in-url-rewrite-module
<rewrites>
<rules>
<rule name="Redirect Rule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{StaticRedirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="http://www.example.com{C:1}" appendQueryString="False" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="StaticRedirects">
<add key="Page.aspx?id=12345" value="/newPage.aspx" />
</rewriteMap>
</rewriteMaps>
</rewrites>
I can add as many redirects as I like in the rewrite map section by adding additional keys.

How do I add a querystring to show user language (?lang=es-MX) using IIS7 Rewrite 2.0?

I have a website (Visual Studio / VB / ASP.NET 4.0) and I have it localized with 9 different languages, so 9 different .resx files in my Apps_GlobalResources directory. The languages works great, and the end-user may manually select the language they want to view.
The Problem:
When a user is on the home page, for example, they're on domain/default.aspx. When they switch to Spanish - Mexican, the page switches to spanish-Mexican, but the URL stays the same -- domain/default.aspx.
It's been recommended by many that I show the end user a querystring. So I want the URL to look like domain/default.aspx?lang=es-MX or domain//es-MX/default.aspx (preferred).
Since all my resource files are in place, can I accomplish this via the II7 rewrite tool? If so, can somebody please explain how I can go about doing it? I'm not familiar with negotiating IIS. Thank you and I'd sincerely appreciate any guidance you can offer!
you can modify web.config files and it'll handle the rewrite for you:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="rule1" stopProcessing="true">
<match url="^(.*)-htm-(.*)" />
<action type="Rewrite" url="{R:1}.php?{R:2}" />
</rule>
<rule name="rule2" stopProcessing="true">
<match url="^(.*)/show-([0-9]+)([\-])?([0-9]+)?\.html" />
<action type="Rewrite" url="{R:1}/show.php?itemid={R:2}&page={R:4}" />
</rule>
<rule name="rule3" stopProcessing="true">
<match url="^(.*)/list-([0-9]+)([\-])?([0-9]+)?\.html" />
<action type="Rewrite" url="{R:1}/list.php?catid={R:2}&page={R:4}" />
</rule>
<rule name="rule4" stopProcessing="true">
<match url="^(.*)/show/([0-9]+)/([0-9]+)?([/])?" />
<action type="Rewrite" url="{R:1}/show.php?itemid={R:2}&page={R:3}" />
</rule>
<rule name="rule5" stopProcessing="true">
<match url="^(.*)/list/([0-9]+)/([0-9]+)?([/])?" />
<action type="Rewrite" url="{R:1}/list.php?catid={R:2}&page={R:3}" />
</rule>
<rule name="rule6" stopProcessing="true">
<match url="^([a-z0-9]+)\.co/(.*)" />
<action type="Rewrite" url="company/index.php?homepage={R:1}&rewrite={R:2}" />
</rule>
<rule name="rule7" stopProcessing="true">
<match url="^(htm)/(.*)" />
<action type="Rewrite" url="index.php?rewrite={R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
here's something you can read:
http://gyansangrah.com/ArticleContent.aspx?ID=URLREWRITINGUSINGHTTPMODULES

How can I correctly rewrite a URL with .aspx to a URL without .aspx?

I have a site that currently uses the .aspx extension on its pages. It's getting a Joomla conversion and the .aspx extension will not work anymore. I need it so that if someone enters the .aspx extension, it will just get removed the URL so none of the SEO on the current site breaks.
For example, I need
www.arrc.com.php5-17.websitetestlink.com/services/managed-services.aspx
to be rewritten/redirected to
www.arrc.com.php5-17.websitetestlink.com/services/managed-services
This is what I have in my web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Migrate to PHP">
<match url="^([_0-9a-z-]+)\.aspx" />
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
<rule name="Rewrite .aspx">
<match url="^([_0-9a-z-]+)/?([_0-9a-z-]+)\.aspx" />
<action type="Redirect" redirectType="Permanent" url="{R:1}/{R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The first URL match is for any URLs that have a URL like services.aspx instead of services/managed-services.aspx
Whenever I go to www.arrc.com.php5-17.websitetestlink.com/services/managed-services.aspx it gives me an internal server error, but www.arrc.com.php5-17.websitetestlink.com/services.aspx rewrites correctly. What can I do to fix this?
They are greedy, switch the order.
<rule name="Rewrite .aspx">
<match url="^([_0-9a-z-]+)/?([_0-9a-z-]+)\.aspx" />
<action type="Redirect" redirectType="Permanent" url="{R:1}/{R:2}" />
</rule>
<rule name="Migrate to PHP">
<match url="^([_0-9a-z-]+)\.aspx" />
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
Two potential issues:
I think for rewriting, it's going to hit them in order, which means the first rule is going to always kick off. Try switching the order of the rule.
The dash should work correctly in [_0-9a-z-], but try escaping the dash.

Resources