Created
March 29, 2010 15:08
-
-
Save fujiwara/347931 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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