Having trouble with web.config redirect; 500 internal server error - redirect

I've created a new website and some old links don't work so I want to redirect those links to my new homepage with anchor tags. I have tried so many code snippets but nothing is working. Can anyone see what I've done wrong (I'm not a programmer) thanks! -
I just get:
500 - Internal server error. There is a problem with the resource you
are looking for, and it cannot be displayed.
Here is my code:
<location path="page_contact.html">
<system.webServer>
<httpRedirect enabled="true" destination="http://www.mywebsite.com/index.html#contact" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<location path="portfolio.html">
<system.webServer>
<httpRedirect enabled="true" destination="http://www.mywebsite.com/index.html#portfolio" httpResponseStatus="Permanent" />
</system.webServer>
</location>

Related

how passing parameter ?id=x inside location path web.config

I'm trying to redirect from web.config using this structure:
<location path="name-page.asp?id=1">
<system.webServer>
<httpRedirect enabled="true" destination="new-page.asp" httpResponseStatus="Permanent" />
</system.webServer>
</location>
But I get an error in name-page.asp?Id=1 because you can't use the "?" parameter, at least i think. How can I get around?

Simple 301 Redirect in Web.Config (IIS)

I've browser a lot of similar questions here, but most have complicated parameters associated with them. I'm just looking to 301 redirect one link to another on the same domain. The to and from links are very specific, so I don't need to account for any wildcards.
In web.config what would be the appropriate way to 301 redirect /locations/100-denver to /locations/denver?
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="/test.aspx" value="/test2.aspx" />
<add key="/aboutus.aspx" value="/about" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer>
</configuration>
I was just researching a similar subject and found this answer on another page: enter link description here

httpErrors - Redirect 403 to HTML file - How to?

I am trying to redirect to a html file when I receive a 403 error in my application. This is handled by IIS, so i have added this into my web config:
<httpErrors errorMode="Custom" >
<remove statusCode="403"/>
<error statusCode="403" responseMode="File" path="/500.html"/>
</httpErrors>
Which gives me this error:
You do not have permission to view this directory or page.
However if I change the response mode to ExecuteURL it will redirect to the page. But it will show a http status code of 200, whereas file will keep the 403 error. I just can't get it to redirect to this file.
Can anyone help me fix this issue?
According to the description of the system.webserver/httperrors/error configuration node (https://www.iis.net/configreference/system.webserver/httperrors/error), setting the responseMode attribute to File requires provding an absolute Windows path to the error page. As in the example below:
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="File" >
<remove statusCode="500" />
<error statusCode="500"
prefixLanguageFilePath="C:\Contoso\Content\errors"
path="500.htm" />
</httpErrors>
</system.webServer>
</configuration>

web.config: redirect 301 doesn't work properly

I want to do a 301 redirect for all the requests on one site (also images, documents, and other files) to the homepage of another site.
I tried putting the web.config on the root of the site, and I'd insert this code:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
<httpRedirect enabled="true" destination="http://www.newsite.com/" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
But with this code on the web.config the problem is that if I digit:
http://www.oldsite.com/file.html
The browser redirect me to: http://www.newsite.com/file.html
But I need that all the redirects are on the homepage.
How can I do it?
You need to set exactDestination="true" to make the destination absolute:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
<httpRedirect exactDestination="true" enabled="true" destination="http://www.newsite.com/" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
See: https://www.iis.net/configreference/system.webserver/httpredirect

Using web.config file for redirect

Using only the web.config file, I need to redirect from one domain to another, and I also need to redirect each individual page (there are 25 of them) in my website to its corresponding page under the new domain. And the renamed /index.htm page, which is the home page (same as the domain name alone) and which is /ghostwriter.htm needs to be redirected to its corresponding page, which will also be the new home page.
Thus: http://www.rainbowriting.com/ is the same page as http://www.rainbowriting.com/ghostwriter.htm (the index page).
You need to make sure ASP.NET is handling .htm files (set this in IIS). Then configure web.config:
<configuration>
<location path="oldPage1.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://www.newDomain.com/newPage1.htm" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<location path="oldPage2.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://www.newDomain.com/newPage2.htm" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<!-- etc. -->
</configuration>