0

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

2 Answers 2

8

Not sure about better SEO results, but adding suffix is simple as

        routes.MapRoute(
            "Default",
            "{action}.html",
            new { controller = "Home", action = "Index" }
        );

Just add .html suffix to action parameter placeholder.

For translation, you could use ActionNameAttribute

    [ActionName("kontakt")]
    public ActionResult Contact()
    {
        return View();
    }

With both codes above combined, you get domain.pl/kontakt.html mapped to Home/Contact action.

Sign up to request clarification or add additional context in comments.

Comments

1

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:

[GET("index.html")]
public ActionResult Index()
{
    return View();
}

[GET("/any/url/path/kontakt.html")]
public ActionResult Contact()
{
    return View();
}

[GET("oferta.html")]
public ActionResult Offer()
{
    return View();
}

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.