Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link without trailing slash

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

like image 952
Pete Avatar asked Jul 17 '26 23:07

Pete


1 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:

<a href="@VirtualPathUtility.ToAbsolute("~")">Home</a>
like image 123
Pete Avatar answered Jul 20 '26 12:07

Pete