1

I have an issue with my nginx config for my joomla site.

I want to rewrite/redirect based on the tld used. Example:

  • domain.fr -> domain.com/fr
  • domain.se -> domain.com/se

How can I achieve this?

Bj Blazkowicz
  • 991
  • 1
  • 6
  • 9

1 Answers1

4

You can use regex in server_name in order to get the TLD in a variable:

server_name ~(www\.)?domain\.(?<tld>\w+)$;

Now you can use it:

rewrite ^(.*)$ /$tld/$1;
Florin Asăvoaie
  • 7,057
  • 23
  • 35
  • 2
    The question is about redirecting / rewriting, not about using different web roots. – Tero Kilkanen Aug 21 '14 at 09:51
  • 1
    It was just an example. He asked how to do stuff based on TLD. I showed him how to extract the TLD. If you wanted to help and be constructive, you should have edited my answer. But no, people these days found the downvote button for the single answer that is perfectly valid too. Well, that's where this website goes I guess. I edited the root statement into a rewrite rule, I hope you're happy now. – Florin Asăvoaie Aug 21 '14 at 10:34