I am trying to redirect a specific page from my old domain to a specific page on my new domain. The URLs look like the following:
http://blog.mysite.com/post/2012/05/hungry.aspx
to
http://mynewsite.com/hungry.aspx
I've looked to the Web.Config file to make this change, however the following code is not working:
<location path="post/2012/05/hungry.aspx">
<system.webServer>
<httpRedirect enabled="true" destination="http://mynewsite.com/hungry.aspx" httpResponseStatus="Permanent" />
</system.webServer>
</location>
When I visit my old blog page, it does no redirection and remains on the old blog page.
Am I missing something?
If http redirection is enabled on old server then you have to put new web config in folder post/2012/05/ with this content
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="http://mynewsite.com/" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
btw. if all other options fails you could simply do that using Response.Redirect from code behind.
Related
We have a domain (domain.com) that has an alias (alias.com). We are using Plesk and a Windows Server. In Plesk, alias.com is setup as an alias for domain.com.
We need that when people access to alias.com it goes to a certain page within the main domain, for example domain.com/this-page.html.
The web site is an ASP.NET MVC web site, in case we can do something using the web.config.
Is this possible? How can we do this?
Open web.config in the directory where the old pages reside
Then add code for the old location path and new destination as follows:
<configuration>
<location path="services.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://example.com/services" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<location path="products.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://example.com/products" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
I have a web app that I'm decommissioning and I'm trying to redirect all requests to the old app to a particular page (which shows a link to the replacement and a message advising users to update their bookmarks).
I've set up a HTTP Redirect in the web.config using the answer from this question: ASP.NET httpRedirect : redirect all pages except one and it works except for when the user enters the URL of the site's root folder omitting the trailing slash, in which case it goes to the next directory up the tree, for example:
Original site root: [domain]/foo/bar/
[domain]/foo/bar/specificpage.aspx redirects to [domain]/foo/bar/Default.aspx (OK)
[domain]/foo/bar/ redirects to [domain]/foo/bar/Default.aspx (OK)
[domain]/foo/bar redirects to [domain]/foo/Default.aspx (not OK)
Here's the relevant web.config:
<system.webServer>
<httpRedirect enabled="true" destination="~/Default.aspx" httpResponseStatus="Permanent">
<add wildcard="/" destination="Default.aspx" />
</httpRedirect>
</system.webServer>
<location path="Default.aspx">
<system.webServer>
<httpRedirect enabled="false" />
</system.webServer>
</location>
How can I get it to work when the user goes to [domain]/foo/bar?
For the record, I fixed this by setting the redirect URL to the absolute path of the file, including the virtual directory the site root sits in:
<system.webServer>
<httpRedirect enabled="true" destination="/foo/bar/Default.aspx" httpResponseStatus="Permanent" exactDestination="true">
<add wildcard="/" destination="Default.aspx" />
</httpRedirect>
</system.webServer>
<location path="Default.aspx">
<system.webServer>
<httpRedirect enabled="false" />
</system.webServer>
</location>
I have a few (4) links that need to be redirected in a .net website. For example, I need http://www.example.com/products/productname (which now longer exists) to redirect to http://www.example.com/products/productname.aspx.
How can I set up 301 redirects in the web.config?
Thanks!
Currently I have the following:
<location path="draft_root_beer">
<system.webServer>
<httpRedirect enabled="true" destination="~/products/draft_root_beer.aspx" httpResponseStatus="Permanent" />
</system.webServer>
</location>
If it is only adding ".aspx", I suggest you to use URL Rewriting, links will be better for SEO. Otherwise yous something like bellow:
<location path="productname">
<system.webServer>
<httpRedirect enabled="true" destination="http://www.example.com/products/productname.aspx" httpResponseStatus="Permanent" />
</system.webServer>
</location>
In my ASP.Net website I am permanently redirecting an URL to other location using <httpRedirect> in web config.
I am reading URL value from table and redirecting to that URL using Response.Redirect( URL );
It is working perfect.
But now when I try to send the parameter to the calling page using:
Response.Redirect("Default.aspx?name=stackoverflow");
<httpRedirect> in web.config calles the Default2.aspx because of following code in web.config:
<location path="Default.aspx">
<system.webServer>
<httpRedirect enabled="true" destination="Default2.aspx" httpResponseStatus="Permanent" />
</system.webServer>
</location>
The Problem is Default2.aspx does not receive any parameters.
Please help.
Note: I cannot use session variable as page contents depends on that parameter.
For instance,
If user opens another page in new tab with Default.aspx?name=MetaStackOverflow session variable will get replaced and if first page is refreshed then instead of showing Stackoverflow content it will show MetaStackOverflow.
Don't forget the special characters $V$Q and the exactDestination has to be set to True.
<location path="Help">
<system.webServer>
<httpRedirect enabled="true" destination="/Redirect.aspx$V$Q" httpResponseStatus="Permanent" exactDestination="true" />
</system.webServer>
</location>
I am trying to redirect a url to a subfolder, for example:
http://localhost/test is what the user will input, but I want that to redirect to http://localhost/test/public
I can't find any resource on the web, and most resources I found is on Apache which doesn't help.
Thanks.
PlayKid
In your web.config file in the Root of the site you would put something like this:
<?xml version="1.0"?>
<configuration>
<location path="test">
<system.webServer>
<httpRedirect enabled="true" destination="test/public" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>