# Htaccess to nginx

**URL:** <https://www.ruby-forum.com/t/htaccess-to-nginx/215955>\
**Category:** NGINX\
**Created:** [January 20, 2012, 1:14pm UTC](https://www.ruby-forum.com/t/htaccess-to-nginx/215955 "2012-01-20T13:14:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [January 20, 2012, 1:14pm UTC](https://www.ruby-forum.com/t/htaccess-to-nginx/215955/1 "2012-01-20T13:14:39Z")

</div>

Hey guys!

i have following htaccess but now i need it for nginx

can some one convert it correct to nginx so that ther are no security  
risks?

ErrorDocument 404 /404.html  
AddDefaultCharset utf-8  
AddCharset utf-8 .html .php .css  
Options FollowSymLinks

AddHandler application/x-httpd-php .html  
\<FilesMatch “.(htm|html|php)$”\>  
AddDefaultCharset UTF-8

# php\_value auto\_prepend\_file

/home/webpages/lima-city/deineagentur/html/DeineAgentur/zip\_output\_header.php

RewriteEngine On

# RewriteCond %{HTTP\_HOST} !^oceangame.deineagentur.com$ [NC]

# RewriteRule ^(.\*)$ [http://oceangame.deineagentur.com/$1](http://oceangame.deineagentur.com/$1) [L,R=301]

RewriteCond %{REQUEST\_METHOD} ^(TRACE|TRACK|OPTIONS|HEAD)$ [NC]  
RewriteRule ^.\*$ - [L,F]

####################

# URI redirections

####################

# Move to [www.example.com](http://www.example.com) (we don’t wanna serve this page without the

subdomain www)  
RewriteCond %{HTTP\_HOST} !^[oceangame.deineagentur.com](http://oceangame.deineagentur.com) [NC]  
RewriteRule ^.\*$ [http://oceangame.deineagentur.com](http://oceangame.deineagentur.com)%{REQUEST\_URI}  
[L,NC,R=301]

# If so, then load language defined by cookie

RewriteCond %{REQUEST\_URI} ^/$  
RewriteCond %{HTTP\_COOKIE} lang=([a-z]{2})  
RewriteRule ^.\*$ /%1 [L,NC,QSA,R=301]

# Add a trailing slash to the request uri if /de was requested without

one  
RewriteCond %{REQUEST\_URI} ^/(de|en|fr|es|it)$  
RewriteRule ^.\*$ /%1/ [L,NC,QSA,R=301]

####################################

# Request the appropriate language

####################################

# German

RewriteCond %{REQUEST\_URI} ^/de(/)?$  
RewriteRule ^de/?.\*$ /system.php?og\_\_site=index  
[L,NC,QSA,E=LANGNAME:de,E=SYSTEM:portal]  
RewriteCond %{REQUEST\_URI} ^/de/([a-z]+).html$  
RewriteRule ^de/([a-z]+).html$ /system.php?og\_\_site=$1  
[L,NC,QSA,E=LANGNAME:de,E=SYSTEM:portal]

# English

RewriteCond %{REQUEST\_URI} ^/en(/)?$  
RewriteRule ^en/?.\*$ /system.php?og\_\_site=index  
[L,NC,QSA,E=LANGNAME:en,E=SYSTEM:portal]  
RewriteCond %{REQUEST\_URI} ^/en/([a-z]+).html$  
RewriteRule ^en/([a-z]+).html$ /system.php?og\_\_site=$1  
[L,NC,QSA,E=LANGNAME:en,E=SYSTEM:portal]

# French

RewriteCond %{REQUEST\_URI} ^/fr(/)?$  
RewriteRule ^fr/?.\*$ /system.php?og\_\_site=index  
[L,NC,QSA,E=LANGNAME:fr,E=SYSTEM:portal]  
RewriteCond %{REQUEST\_URI} ^/fr/([a-z]+).html$  
RewriteRule ^fr/([a-z]+).html$ /system.php?og\_\_site=$1  
[L,NC,QSA,E=LANGNAME:fr,E=SYSTEM:portal]

# Spain

RewriteCond %{REQUEST\_URI} ^/es(/)?$  
RewriteRule ^es/?.\*$ /system.php?og\_\_site=index  
[L,NC,QSA,E=LANGNAME:es,E=SYSTEM:portal]  
RewriteCond %{REQUEST\_URI} ^/es/([a-z]+).html$  
RewriteRule ^es/([a-z]+).html$ /system.php?og\_\_site=$1  
[L,NC,QSA,E=LANGNAME:es,E=SYSTEM:portal]

# Italian

RewriteCond %{REQUEST\_URI} ^/it(/)?$  
RewriteRule ^it/?.\*$ /system.php?og\_\_site=index  
[L,NC,QSA,E=LANGNAME:it,E=SYSTEM:portal]  
RewriteCond %{REQUEST\_URI} ^/it/([a-z]+).html$  
RewriteRule ^it/([a-z]+).html$ /system.php?og\_\_site=$1  
[L,NC,QSA,E=LANGNAME:it,E=SYSTEM:portal]

########################

# Serving normal files

########################

# Request language specific sitemap.xml

RewriteCond %{REQUEST\_URI} ^/(de|en|fr|es|it)/sitemap.xml$  
RewriteRule ^(de|en|fr|es|it)/.\*$ /sitemap\_$1.xml [L,NC]

# Request normal files like images or style sheets

RewriteCond %{IS\_SUBREQ} false  
RewriteRule ^(?:de|en|fr|es|it)/(.\*)$ /$1 [L,NC,QSA,R=301]

# Move to index.php if the requested file doesn’t exist

RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteCond %{REQUEST\_FILENAME} !-d  
RewriteRule ^.\*$ [http://oceangame.deineagentur.com](http://oceangame.deineagentur.com) [L,NC,QSA,R=301]

Posted at Nginx Forum:

> **[htaccess to nginx](https://forum.nginx.org/read.php?2,221476,221476#msg-221476)**
>
> Hey guys! i have following htaccess but now i need it for nginx can some one convert it correct to nginx so that ther are no security risks? ErrorDocument 404 /404.html AddDefaultCharset utf-8 AddCharset utf-8 .html .php .css
