[英]Redirect from a 404 page to new page using ASP.Net
Apologies if this has been asked...couldn't find any good answers. 如果有人问过这个道歉......找不到任何好的答案。 There are some ASP tutorials that shows this code:
有一些ASP教程显示了这段代码:
<%
Response.Redirect "http://www.w3schools.com"
%>
but where do I put that code at if the original file is non-existant? 但是如果原始文件不存在,我该把代码放在哪里? and don't I have to put the original file into the code to tell the server to go from OLD file to NEW file if people try to access the old file?
如果人们试图访问旧文件,我不必将原始文件放入代码中告诉服务器从OLD文件转到新文件?
I know how to do a redirect for a server which can accept redirects using PHP in an .htaccess file. 我知道如何对服务器进行重定向,该服务器可以在.htaccess文件中使用PHP接受重定向。 But this site I am working on won't accept the code I have which usually works.
但我正在研究的这个网站不会接受我通常使用的代码。
The 404 page will show: 404页面将显示:
Server Error in '/pagehere' Application. '/ pagehere'应用程序中的服务器错误。 The resource cannot be found.
无法找到该资源。 Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.
说明:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。 Please review the following URL and make sure that it is spelled correctly.
请查看以下网址,确保拼写正确。
Requested URL: /pagehere 请求的URL:/ pagehere
Version Information: Microsoft .NET Framework Version:4.0.30319; 版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET Version:4.0.30319.34280
ASP.NET版本:4.0.30319.34280
I want to do a redirect from oldpage.php to newpage.php. 我想从oldpage.php重定向到newpage.php。 oldpage.php is no longer existing.
oldpage.php不再存在。
Whate file do I create or edit and what code would I use for the redirect? 我创建或编辑Whate文件以及我将使用哪些代码进行重定向? Thanks!
谢谢!
If you can control your web.config , you can add in permanent redirects. 如果您可以控制web.config ,则可以添加永久重定向。
A decent quick reference is at https://www.stokia.com/support/misc/web-config-response-redirect.aspx 一个不错的快速参考是https://www.stokia.com/support/misc/web-config-response-redirect.aspx
From that site, you can do individual redirects. 从该站点,您可以进行单独的重定向。
<configuration>
<location path="bing.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://bing.com" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<location path="google.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://google.com" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<location path="yahoo.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://yahoo.com" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
Here you would place oldpage.html under the location
tag. 在这里,您可以将oldpage.html放在
location
标记下。
<location path="oldpage.html">
Then you would place newpage.html uder the httpRedirect
tag. 然后你将newpage.html
httpRedirect
标签上。
<httpRedirect enabled="true" destination="newpage.html" httpResponseStatus="Permanent" />
Combined like this. 结合这样。
<location path="oldpage.html">
<system.webServer>
<httpRedirect enabled="true" destination="newpage.html" httpResponseStatus="Permanent" />
</system.webServer>
</location>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.