I use the following in MVC to create a link to my home page in my application:
<a href="~/">home</a>
Unfortunately, when this is run under an app, this will create a link like
<a href="/app-name/">home</a>
Is there a way to create this link to the app-name
without the trailing slash (or without just hardcoding the it)?
Our site is canonicalised so that any urls with a trailing slash end up being redirected to their non trailing slash version and because this link has a trailing slash on, it is causing unnecessary redirect hops, which is penalising our seo ratings
2
Answers
Thanks to the comment from Lajos Arpad, it got me of thinking into another of making up the url so I thought if I use the
VirtualPathUtility.ToAbsolute
I may be able to then substring the result.But using the following meant I didn't need to substring to get the url I needed:
The Html.ActionLink helper should generate a link that conforms to your requirements:
Assuming your homepage is called “Index” and rendered by the “HomeController”.