# YA Converting .htaccess to nginx, I can't get it to work!

**URL:** <https://www.ruby-forum.com/t/ya-converting-htaccess-to-nginx-i-cant-get-it-to-work/229849>\
**Category:** NGINX\
**Created:** [February 5, 2013, 4:24am UTC](https://www.ruby-forum.com/t/ya-converting-htaccess-to-nginx-i-cant-get-it-to-work/229849 "2013-02-05T04:24:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![otherjohn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@otherjohn](https://www.ruby-forum.com/u/otherjohn)\
**Post date:** [February 5, 2013, 4:24am UTC](https://www.ruby-forum.com/t/ya-converting-htaccess-to-nginx-i-cant-get-it-to-work/229849/1 "2013-02-05T04:24:25Z")

</div>

Hi all,  
I am trying to convert this htaccess file to nginx config and it is not  
working.  
Here is my .htaccess

 Header unset ETag FileETag None Header unset Last-Modified Header set Expires "Fri, 21 Dec 2020 00:00:00 GMT" Header set Cache-Control "public, no-transform" RewriteEngine On RewriteCond %{QUERY\_STRING} ^$ RewriteRule ^((.)?)$ index.php?p=home [L]

```
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^(.*)$ $1 [QSA,L]

    RewriteCond $1

```

!^(#(.)_|?(.)_|.htaccess(.)_|.htaccess.back(.)_|.idea/(.)_|.svn/(.)_|admin.php(.)_|content/(.)_|download.php(.)_|ecc/(.)_|images/(.)_|index.php(.)_|install/(.)_|login.php(.)_|readme.txt(.)_|robots.txt(.)_)  
RewriteRule ^(.+)$ index.php?url=$1&%{QUERY\_STRING} [L]

 SetOutputFilter DEFLATE 

and here is my config. I can get it to somewhat work if I only use one  
of  
the following lines but then the rest is broke!

location / {  
if ($query\_string ~ “^$”){  
rewrite ^/((.)?)$ /index.php?p=home break;  
}  
if (-e $request\_filename){  
rewrite ^(.\*)$ /$1 break;  
}  
rewrite ^(.+)$ /index.php?url=$1&$query\_string break;  
location ~ .php$ {  
try\_files $uri =404;  
fastcgi\_pass unix:/tmp/php5-fpm.sock;  
fastcgi\_index index.php;  
include /etc/nginx/fastcgi\_params;  
}

}

Not to mention that I hate using the if else clauses in my nginx config  
because I think I read where it is poor for performance.

Can someone give me a hand here. I have been working on this for hours  
without any luck.  
John

Posted at Nginx Forum:

> **[YA Converting .htaccess to nginx, I can't get it to work!](https://forum.nginx.org/read.php?2,235905,235905#msg-235905)**
>
> Hi all, I am trying to convert this htaccess file to nginx config and it is not working. Here is my .htaccess \<IfModule mod\_headers.c\> Header unset ETag FileETag None \<FilesMatch "(?i)^.\*\\.(ico|flv|jpg|jpeg|png|
