Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a site I want users to load pages under "es" directory, i.e., For example:

Users should see: but is loaded

Users see but is loaded

I tried

server {
    listen 80;
    return 301 $scheme://$request_uri;

server {
    listen 80;
    limit_conn arbeit 32;

    rewrite ^(.*)$ http://$host/es/$1 permanent;

    ## Access and error logs.
    access_log /var/log/nginx/spanish.com_access.log;
    error_log /var/log/nginx/spanish.com_error.log;


but it results to infinite redirects to

also, how do you exclude files from the rewrite rule? Like in apache?

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
share|improve this question

This is how I got through it:

## for the homepage
location = / {
    rewrite ^ /es;

## for the rest of the pages, excluding locations beginning
## with /<2char-lang-prefix>/*
## also excludes locations having only 3 characters, e.g. "/nb"
location ~* "^/(?!.{2,2}/).{3}.*$" {
    rewrite "^/(.*)$" /es/$1;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.