ASP.NET MVC - 301 重定向 - SEO 问题
所以我有一个像这样的 ActionName:
[ActionName("Chicago-Bears")]
public ActionResult ChicagoBears() {
return View();
}
Google 将此索引为: http://www.example.com/Teams /ChicagoBears
我无法使用 IIS6,并且自己无法访问 IIS。
当然,现在它里面有一个连字符。因此,如果有人点击该链接,Google 将显示 404。
在这种情况下如何设置 301 重定向?我无法创建另一个名为 ChicagoBears() 的方法,所以...
谢谢大家。
So I have an ActionName like so:
[ActionName("Chicago-Bears")]
public ActionResult ChicagoBears() {
return View();
}
Google has this indexed as: http://www.example.com/Teams/ChicagoBears
I'm stuck using IIS6 and have no access to IIS myself.
Of course now, it has a hyphen in it. So, Google will show a 404 if someone clicks on that link.
How do I setup a 301 redirect in this instance? I can't create another method called ChicagoBears(), so...
Thanks guys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为 Teams/ChicagoBears 创建一条指向提供永久重定向的操作的路线。
在 Global.asax 中...
在 TeamsController 中...
Create a route for Teams/ChicagoBears that points to an action that gives a permanent redirect.
In Global.asax...
In TeamsController...
URL 重写模块是您的朋友。学习它,生活它,热爱它...
http ://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
当我从 DasBlog 迁移到 WordPress 时,我广泛使用了它。我所有的旧博客 URL 都使用 301 重定向到新的 URL。强烈推荐。
更新:IIS6 有 URL 重写器。快速谷歌搜索出现:
(通过 http://forums.iis.net/t/1160436.aspx。)
The URL Re-Write Module is your friend. Learn it, live it, love it...
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
I used it extensively when I migrated from DasBlog to WordPress. All my old blog URLs are re-directed using 301's to the new ones. Highly recommended.
UPDATE: There are URL re-writers for IIS6. A quick google search turned up:
(Found via http://forums.iis.net/t/1160436.aspx.)
更新:我引用的这个博客似乎不再可用,因此我更新了链接以引用互联网存档版本。
查看此博客文章以获得出色的解决方案*:https://web.archive.org/web/20160528185929/http://www.eworldui.net/blog/post/2008/04/ 25/ASPNET-MVC-Legacy-Url-Routing.aspx
本质上他所做的是创建一个可用于多个路由的可重用类,并且它们只是向指定的 Action 方法发出永久重定向。
**注意:这不是我的博客,而是我偶然发现的一个。*
UPDATE: This blog I referenced seems to no longer be available so I updated the link to reference the internet archive version.
Check out this blog post for a great solution*: https://web.archive.org/web/20160528185929/http://www.eworldui.net/blog/post/2008/04/25/ASPNET-MVC-Legacy-Url-Routing.aspx
Essentially what he is doing is creating a reusable class that can be used for multiple routes, and they just issue a permanent redirect to the specified Action method.
**Note: This is not my blog, but one that I simply came across.*
在这个聚会上有点晚了,但我写了 关于旧路由永久重定向的博客文章,允许此操作 -
要重定向到的
Location
是使用Url.Action 使用路由值生成的
,因此只要 RouteTable 中有与路由值匹配的路由,301 重定向就会按预期工作。在您的示例中,当 URL 模式与"Teams/ChicagoBears"
匹配时,生成的 URL 应为http://www.example.com/Teams/Chicago-Bears
。我不会在这里重复代码,因为博客上有很多代码
Little late to the party on this one, but I wrote a blog post about permanent redirects for legacy routes that allows this -
The
Location
to redirect to is generated using the route values usingUrl.Action
, so as long as you have a route in the RouteTable that matches the route values, the 301 redirect will work as intended. In your example, the generated URL should behttp://www.example.com/Teams/Chicago-Bears
when the URL pattern matches"Teams/ChicagoBears"
.I won't repeat the code here as there's quite a bit and it's on the blog