如何移动 ASP.NET MVC 站点的 URL
我的 SEO 同事发出了一些涉及移动
www.mydomain.co.uk/news
的 URL 请求 www.mydomain.co.uk/news/{id}/{title}
至
www.mydomain.co.uk/uk-news
www.mydomain.co.uk/uk-news/{id}/{title}
执行此操作的最佳方法是什么?
我只是想更改 global.asax 文件中的路由
FROM:
routes.MapRoute(
"News", // Route name
"News", // URL with parameters
new { controller = "News", action = "Index" } // Parameter defaults
);
TO:
routes.MapRoute(
"News", // Route name
"uk-news", // URL with parameters
new { controller = "News", action = "Index" } // Parameter defaults
);
并在基本 www.mydomain.co.uk/news 上设置 301 重定向
有没有更好的方法来做到这一点?
My SEO colleague has fired in a few url requests that involve moving
www.mydomain.co.uk/news
www.mydomain.co.uk/news/{id}/{title}
to
www.mydomain.co.uk/uk-news
www.mydomain.co.uk/uk-news/{id}/{title}
What is the best way to carry this out.
I was just thinking of changing the route in the global.asax file
FROM:
routes.MapRoute(
"News", // Route name
"News", // URL with parameters
new { controller = "News", action = "Index" } // Parameter defaults
);
TO:
routes.MapRoute(
"News", // Route name
"uk-news", // URL with parameters
new { controller = "News", action = "Index" } // Parameter defaults
);
and setting up a 301 redirect on the basic www.mydomain.co.uk/news
Is there a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不这么认为。您的方向是正确的,更改路由上的 URL 并执行 301 永久重定向是正确的方法。对于 301,请尝试使用 URL 重写模块。
重写模块
ISAPI_Rewrite
I(忽略大小写)
表示无论大小写,都匹配字符。该标志影响 RewriteHeader 指令和所有相应的 RewriteCond 指令。
O (nOrmalize)
在处理之前规范化字符串。规范化包括删除 URL 编码、非法字符等。此外,URI 的 IIS 规范化会完全删除查询字符串。因此,如果需要查询字符串,则不应使用规范化。此标志对于 URL 和 URL 编码标头很有用。
RP(永久重定向)
几乎与 [R] 标志相同,但发出 301(永久移动)HTTP 状态代码而不是 302(临时移动)。
L(最后一条规则)
在此停止重写过程,并且不再应用任何重写规则。
I don't think so. Your on the right track, changing the URL on the route and doing the 301 permanent redirect is the way to go. For the 301 try using the URL Rewrite Module.
Rewrite Module
ISAPI_Rewrite
I (ignore case)
Indicates that characters are matched regardless of a case. This flag affects RewriteHeader directive and all corresponding RewriteCond directives.
O (nOrmalize)
Normalizes string before processing. Normalization includes removing of an URL-encoding, illegal characters, etc. Also, IIS normalization of an URI completely removes query string. So, normalization should not be used if query string is needed. This flag is useful with URLs and URL-encoded headers.
RP (permanent redirect)
Almost the same as the [R] flag but issues 301 (moved permanently) HTTP status code instead of 302 (moved temporary).
L (last rule)
Stop the rewriting process here and don't apply any more rewriting rules.