Skip to content

Instantly share code, notes, and snippets.

@fujiwara
Created March 29, 2010 15:08
Show Gist options
  • Save fujiwara/347931 to your computer and use it in GitHub Desktop.
Save fujiwara/347931 to your computer and use it in GitHub Desktop.
package SwitchByLang;
use strict;
use nginx;
sub handler {
my $r = shift;
my $uri = $r->uri;
if ($uri =~ qr{^/(en|ja)/}) {
return DECLINED;
}
my $lang = "en";
if ($r->header_in("Accept-Language") =~ qr{(en|ja)}) {
$lang = $1;
}
$uri =~ s{^/(.*)}{/$lang/$1};
$r->internal_redirect($uri);
return OK;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment