I'm working on a multilingual Asp.Net MVC project. Default language is Turkish and alternate language is English. I need to make urls seo friendly. For example some urls for web site are like;
Home/About:
- www.example.com/hakkinda
- www.example.com/about
Home/Contact:
- www.example.com/iletisim
- www.example.com/contact
Home/Faq :
- www.example.com/sikca-sorulan-sorular
- www.example.com/frequently-asked-questions
There are some pages like this. I also have Turkish and English seo friendly urls for the pages.
I register routes:
routes.MapRoute(
name: "hakkinda",
url: "hakkinda",
defaults: new { controller = "Home", action = "About"}
);
routes.MapRoute(
name: "about",
url: "about",
defaults: new { controller = "Home", action = "About"}
);
routes.MapRoute(
name: "iletisim",
url: "iletisim",
defaults: new { controller = "Home", action = "Contact"}
);
routes.MapRoute(
name: "contact",
url: "contact",
defaults: new { controller = "Home", action = "Contact"}
);
routes.MapRoute(
name: "sss",
url: "sikca-sorulan-sorular",
defaults: new { controller = "Home", action = "Faq"}
);
routes.MapRoute(
name: "faq",
url: "frequently-asked-questions",
defaults: new { controller = "Home", action = "Faq"}
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home",
action = "Index", id = UrlParameter.Optional }
);
I also have a Home/ChangeLanguage method, which sets thread's culture by given culture name (tr/en) User can change language by clicking a button
My first question is i need to change url automatically when user changes language.
Initial url : www.example.com/hakkinda After user changes language to English url should redirect to www.example.com/about Again if user changes language to back to Turkish it should be redirected to www.example.com/hakkinda This has to be applied to all pages.
My second question is for Seo optimization, i need to add below tags to all pages in order to say bots alternate pages by language
<link rel="alternate" hreflang="tr" href="http://www.example.com/hakkinda"/>
<link rel="alternate" hreflang="en" href="http://www.example.com/about"/>
I need to add these link tags to Site Layout and it must be matched with the current url.
Could you please give advice about how i can achieve these ?
-
did you find a good solution?daniel– daniel2015年10月20日 13:02:39 +00:00Commented Oct 20, 2015 at 13:02
1 Answer 1
You could create an ActionFilter that will given each request check the culture sent to the server (done via cookie?) and then have it on every request look up the controller and action against separate dictionaries, try to match the oposite localisation on either the controller or Action and if it hits a match (i.e. your currently navigating to /about but your in Turkish, it would match /about as being english and then perform a redirect to /hakkinda
Comments
Explore related questions
See similar questions with these tags.