How to make an aspx page do a httpredirect? - redirect

I'm trying to redirect an aspx page to another aspx page. But only as the aspx page get's called without any parameters.
So when it's called like this: https://www.a.com/test.aspx?param=1 it doesn't have to do anyhthing.
But when it's called like this: https://www.a.com/test.aspx it has to redirect.
I tried this, but it doesn't redirect, instead, it executes the aspx.
<system.webServer>
<httpRedirect enabled="true" httpResponseStatus="Found" exactDestination="true">
<add wildcard="*test.aspx" destination="/destination.aspx"/>
</httpRedirect>
</system.webserver>
Any ideas?
extra info: it's from a https domain.
I also tried the following, but this makes it crash hard:
<rewrite>
<rules>
<rule name="myrule" stopProcessing="true">
<match url="/test.aspx" />
<action
type="Redirect"
url="/destination.aspx"
appendQueryString="false"
redirectType="Found" />
</rule>
</rules>
</rewrite>

One way to do it would using code in the page load of your ASPX page. If no querystring are provided, then do your redirect.
If you want to do the redirect earlier, you can also use the global.asax BeginRequest event to redirect (check the current request's URI and redirect if needed).

Related

How do I solve a 403 or redirect error in IIS Manager

403 or redirect error keeps appearing in the browser even though I have done my redirects properly in IIS Manager. I have tried clearing my cookies, this did not work.
Edit: enabled direct browsing in IIS Manager and this is the result (the fifth image)
redirect checked
result of redirect checked
redirect not checked
result of redirect not checked
result of enabling direct browsing
Try to use the redirect function in the URL Rewrite module:
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP}" pattern="off" />
</conditions>
<action type="Redirect" url="http://www.example.com" />
</rule>
</rules>
</rewrite>
If you haven’t installed URL Rewrite yet, you can download URL Rewrite from this link.

Web.config mass 301 redirect old news page to a slightly different Urls

I need to redirect a bunch of news articles to a different url format using web.config.
For example, this Url:
https://www.example.com/footer/press-resources/press-releases/press-release-detail/abcd-press-release-item
Should be redirected to this Url:
https://www.example.com/about/press-releases/press-release-detail/abcd-press-release-item
In this example, as you can see this portion of the Url is staying intact /press-release-detail/abcd-press-release-item but everything else before this should be redirected. The only dynamic part of the Url is the article's title which is at the end of the Url, in this case: abcd-press-release-item
I have about 300 items, obviously redirecting them one by one is going to take some time. Is there a way to rule them all out and mass redirect the old Urls to the new ones?
This is a Windows/IIS server with a .NET CMS and a web.config file.
I tried this rule and it didn't work for me:
<rule name="301 Redirect 1" stopProcessing="true">
<match url="^https://www.example.com/footer/press-resources/press-releases/press-release-detail\$" />
<action type="Redirect" url="https://www.example.com/about/press-releases/press-release-detail" redirectType="Permanent" />
</rule>
Try to use this URL Rewrite rule:
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="(footer)/(press-resources)(.*)" />
<action type="Redirect" url="https://www.example.com/about{R:3}" />
</rule>
</rules>
</rewrite>

asp.net MVC And I need to setup 301 redirects

I have a site moving from php to asp.net MVC And I need to setup 301 redirects for it so like www.mystoresitem.com/products/widget1name needs to redirect to www.mystoresitem.com/widget1name for 700+ different widgets how do I redirect this with out doing it for each product/widget.
First of all you need to be sure that you installed URL Rewrite module in your IIS
Then in your web.config just add this rules inside system.webServer section:
<rewrite>
<rules>
<rule name="Redirects to products">
<match url="^products/(.*)" />
<action type="Redirect" url="/{R:1}" />
</rule>
</rules>
</rewrite>
It will automatically redirect all your urls
www.mystoresitem.com/products/{productname} to www.mystoresitem.com/{productname}

Creating a IIS Url Rewrite/Redirect

Im struggling to get a url rewrite/redirect to work in IIS. I've installed the url rewrite module and all the rules fail to do anything. Here is the scenario, we want all web requests which generate a report to be pushed off to a secondary server so it doesn't harm the main box. The web requests that generate reports look something like this:
http://mywebaddress/api/Actionname=GenerateReport&param=123
So im wanting to do some type of regex check on finding any web requests that have "GenerateReport" in it and redirect it to something like:
http://mywebaddressofsecondserver/api/Actionname=GenerateReport&param=123
Any ideas on how the redirect/rewrite would go for this?
You need to check if REQUEST_URI contains Actionname=GenerateReport.
If so, you'll redirect it to other webserver url equivalent.
Translated to an IIS rewrite rule, it would look like this
<rule name="Delegate report generation" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_URI}" pattern="Actionname=GenerateReport" />
</conditions>
<action type="Redirect" url="http://mywebaddressofsecondserver/{R:1}" />
</rule>
Thanks, Justin Iurman,
Your answer solved my issue of getting methods
http://mywebaddress/api/Param/Action1
http://localserverwithport/api/Param/Action1
but for below Post methods it's still giving 404 not found
http://mywebaddress/api/Param/PostAction2
http://localserverwithport/api/Param/PostAction2
Post parameters are:
{"Param1":"James","Param2":"jani"}
My implementation is
'<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Rule1" >
<match url="^(.*)" />
<action type="Redirect" url="http://localserverwithport/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>'

Redirect rule in web.config

I was looking into this Seemingly simple redirect in IIS using web.config file because I have a similar situation, but the approach mentioned there doesn't seem to be working for me.
I have a help section on a web site, which for now I want it to redirect to another place. The rest of the site should stay the same, which means that only the help section/content should make the user go to another site:
device.domain.com/help
device.domain.com/help/version
Should make the request go to
company.custhelp.com
But for example device.domain.com/api should still work. This is what I tried. If I test the pattern inside of IIS it says that it will work. What am I missing?
<system.webServer>
<rewrite>
<rules>
<rule name="Help Redirect" stopProcessing="true">
<match url="(.*)/help(.*)" ignoreCase="true" />
<action type="Redirect" url="http://company.custhelp.com/" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
...
</system.webServer>
The match url will try to match on the path after the domain, starting from after the slash. So it should be like so:
<match url="help(.*)" ignoreCase="true" />
The match url that you wrote would match on device.domain.com/temp/help, but not device.domain.com/help.