在 ASP .NET MVC 3 中重写 Url - 在链接中添加 *.html 后缀
我正在创建简单的应用程序,某种投资组合。我听说链接中最好有 *.html 后缀,因为在 Google 索引时它会给我更好的 SEO 结果...
无论如何,有没有办法修改默认路由/重写 url,以便我的链接看起来像这样(我使用的是波兰语单词,以便访问者可以阅读):
domain.pl/index.html
domain.pl/kontakt.html
domain.pl/oferta.html
domain.pl/sklepy.html
这些链接会被转换为一个控制器(例如 HomeController),但是是来自 {0} 的 {0}。 html 链接,将用作操作 姓名?或者更好的是,我想将 {0} 从网址映射到英文操作名称,例如:
index.html = index action
kontakt.html = contact action
oferta.html = offer action
sklepy.html = shops action
I'm creating simple application, some kind of portfolio. I've heard that it's better to have a *.html suffix in links, as it will get me better SEO results when indexing by Google...
Anyway, is there a way to modify default routing / rewrite url so that my links look like this (I'm using polish words that they are readable for my visitors):
domain.pl/index.html
domain.pl/kontakt.html
domain.pl/oferta.html
domain.pl/sklepy.html
And these links are translated into one controller (like HomeController), but the {0}, from the {0}.html link, will be used as an action name? Or even better, I would like to map {0} from Url to english action names like:
index.html = index action
kontakt.html = contact action
oferta.html = offer action
sklepy.html = shops action
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定是否有更好的 SEO 结果,但添加后缀很简单,
只需将 .html 后缀添加到操作参数占位符即可。
对于翻译,您可以使用
ActionNameAttribute
结合上面的两个代码,您将得到
domain.pl/kontakt.html
映射到Home/Contact
操作。Not sure about better SEO results, but adding suffix is simple as
Just add .html suffix to action parameter placeholder.
For translation, you could use
ActionNameAttribute
With both codes above combined, you get
domain.pl/kontakt.html
mapped toHome/Contact
action.对于翻译和后缀,您可以尝试使用 AttributeRouting。
安装此软件包后,您无需在 Global.asax 中配置路由,控制器将如下所示:
顺便说一句,如果您想删除每个属性上重复的 .html,您可以创建自己的属性扩展 GETAttribute 并附加 .html。如果您有很多页面需要配置,这将很有用。
For both the translation and suffix, you can try using AttributeRouting.
With this package installed, you don't need to configure routes in your Global.asax and the controllers will be like this:
By the way, if you want to remove the duplicated .html on each attribute, you can create your own attribute that extends GETAttribute and append the .html. This would be useful if you have lots of pages to configure.