2

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 ?

asked Sep 15, 2015 at 21:50
1
  • did you find a good solution? Commented Oct 20, 2015 at 13:02

1 Answer 1

0

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

answered Sep 16, 2015 at 0:41
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.