# The Friendly URLs part # detect language when requesting the root (/) RewriteCond %{HTTP:Accept-Language} !^de [NC] RewriteRule ^$ en/ [R=301,L] RewriteRule ^$ de/ [R=301,L] # redirect all requests to /en/favicon.ico and /de/favicon.ico # to /favicon.ico RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(en|de)/favicon.ico$ favicon.ico [L,QSA] # redirect all requests to /en/assets* and /de/assets* to /assets* RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(en|de)/assets(.*)$ assets$2 [L,QSA] # redirect all other requests to /en/* and /de/* # to index.php and set the cultureKey parameter RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(en|de)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
server { listen 80; server_name dummy.***.com; access_log /home/***/public_html/dummy.***.com/log/access.log; error_log /home/***/public_html/dummy.j***.com/log/error.log; root /home/***/public_html/dummy.***.com/public/; location = /favicon.ico { return 204; } location = /favicon.png { } # to serve static files location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico)$ { access_log off; expires 30d; break; } # to serve static files # default PHP Behaviour location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include /usr/local/nginx/conf/fastcgi_params; fastcgi_param SCRIPT_FILENAME /home/***/public_html/dummy.***.com/public/$fastcgi_script_name; } # default PHP Behaviour location / { index index.php index.html; # modx tweak http://modxcms.com/forums/index.php?topic=50615.0 if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?q=$1 last; } # modx tweak } }
server { listen *:80; server_name domain.local www.domain.local; root /var/www/appdir; index index.php; ## add www. for SEO if ($host != 'www.domain.local') { rewrite ^/(.*)$ http://www.domain.local/$1 permanent; } ## set expires headers on known static filetypes and deliver immediately location ~* \.(css|js|jpeg|jpg|gif|png|ico)$ { expires 30d; break; } ## filter out lang prefix, if present ## this block is optional, in case you have i18n URLs like: /de/about-us, /en/about-us, etc. location ~ /(de|en)/ { if (!-e $request_filename) { rewrite ^/(de|en)/(.*)$ /index.php?q=$2 last; } } ## matches any query, since all queries begin with / location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?q=$1 last; } } ## pass php scripts to fastcgi location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME /var/www/appdir$fastcgi_script_name; } ## disable viewing .htaccess & .htpassword location ~ /\.ht { deny all; } }
location / { try_files $uri $uri/ @rewrite; } location @rewrite { rewrite ^/(.*)$ /index.php?q=$1; }
server { listen 443 ssl; server_name www.example.de; charset utf-8; ssl_certificate /etc/ssl/certs/wildcard_example_de_052014_nginx.crt; ssl_certificate_key /etc/ssl/private/wildcard_example_de_052014.key; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-$ ssl_prefer_server_ciphers on; # 1-yr HSTS add_header Strict-Transport-Security max-age=31536000; root /var/www/modx; index index.php; passenger_enabled off; # SinatraApp location ~ ^/sinatraapp { alias /var/www/sinatraapp_api/current/public$1; passenger_base_uri /sinatraapp; passenger_app_root /var/www/sinatraapp_api/current; passenger_document_root /var/www/sinatraapp_api/current/public; passenger_enabled on; } location ~ ^/(partner|integration) { return 301 https://anothersite.example.de$request_uri; } location ~ ^/(de|en)/favicon.ico { rewrite ^/(de|en)/favicon.ico$ /favicon.ico last; } location ~ ^/(de|en)/assets { rewrite ^/(de|en)/assets(.*)$ /assets$2 last; } location ~ ^/(de|en)/ { rewrite ^/(de|en)/(.*)$ /index.php?cultureKey=$1&q=$2 last; } ## matches any query, since all queries begin with / location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?q=$1 last; } } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_ignore_client_abort on; fastcgi_param SERVER_NAME $http_host; } location ~ /\.ht { deny all; } # Limit request body size client_max_body_size 20m; access_log /var/log/nginx/www_example_de_https.access.log; error_log /var/log/nginx/www_example_de_https.error.log }
There is a context switcher plugin that doesn't require any server rewrites, it's all handled in the plugin. https://gist.github.com/gadamiak/3812853