# Help with convert .htaccess to nginx

**URL:** <https://www.ruby-forum.com/t/help-with-convert-htaccess-to-nginx/218786>\
**Category:** NGINX\
**Created:** [April 12, 2012, 5:20am UTC](https://www.ruby-forum.com/t/help-with-convert-htaccess-to-nginx/218786 "2012-04-12T05:20:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gurdipe\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b77776/32.png) [@Gurdipe\_D](https://www.ruby-forum.com/u/Gurdipe_D)\
**Post date:** [April 12, 2012, 5:20am UTC](https://www.ruby-forum.com/t/help-with-convert-htaccess-to-nginx/218786/1 "2012-04-12T05:20:27Z")

</div>

It’s me again ☹ I was trying to install siwapp on my webserver but I  
couldn’t make it work with nginx, here is the .htaccess file content:

```
# If the file is NOT the index.php file
<IfModule mod_rewrite.c>

 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !index.php
 # Hide all PHP files so none can be accessed by HTTP
 RewriteRule (.*)\.php$ index.php/$1

 RewriteCond $1

```

!^(index.php|nhototamsu|assets|cache|xd\_receiver.html|photo|ipanel|automap|xajax\_js|files|robots.txt|favicon.ico|ione.ico|(.\*).xml|ror.xml|tool|google6afb981101589049.html|googlec0d38cf2adbc25bc.html|widget|iradio\_admin|services|wsdl)

```
 RewriteRule ^(.*)$ index.php/$1 [QSA,L]

```

When I access  
[http://myurl.com/tin-tuc/tuyen-sinh/tu-van/2012/04/25757-phan-van-qua-giua-khoi-a1-va-khoi-a.html](http://myurl.com/tin-tuc/tuyen-sinh/tu-van/2012/04/25757-phan-van-qua-giua-khoi-a1-va-khoi-a.html)  
,nginx could display the page correctly, it said: “404 Not Found” (new  
URL:  
[http://myurl.com/tin-tuc/tuyen-sinh/tu-van/2012/04/25757-phan-van-qua-giua-khoi-a1-va-khoi-a.html](http://myurl.com/tin-tuc/tuyen-sinh/tu-van/2012/04/25757-phan-van-qua-giua-khoi-a1-va-khoi-a.html))

Posted at Nginx Forum:

> **[Help with convert .htaccess to nginx](https://forum.nginx.org/read.php?2,225195,225195#msg-225195)**
>
> It's me again :( I was trying to install siwapp on my webserver but I couldn't make it work with nginx, here is the .htaccess file content: # If the file is NOT the index.php file \<IfModule mod\_rewrite.c\> RewriteEngine on RewriteCon

---

<div class="post-metadata">

**Author:** ![haonhien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e9bcb4/32.png) [@haonhien](https://www.ruby-forum.com/u/haonhien)\
**Post date:** [April 12, 2012, 1:31pm UTC](https://www.ruby-forum.com/t/help-with-convert-htaccess-to-nginx/218786/2 "2012-04-12T13:31:56Z")

</div>

You have not provided anything like sufficient information about your  
configuration or the steps you’ve take to debug this.  
_Please_ read this in your mother tongue, apply its lessons, and  
people may be able to help you:  
[http://www.catb.org/~esr/faqs/smart-questions.html#translations](http://www.catb.org/~esr/faqs/smart-questions.html#translations)

## HTH, Jonathan

Jonathan M.  
Oxford, London, UK

> **[Jonathan Matthews :: Words Typed, Great Rates For Cash](https://www.jpluscplusm.com)**

---

<div class="post-metadata">

**Author:** ![haonhien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e9bcb4/32.png) [@haonhien](https://www.ruby-forum.com/u/haonhien)\
**Post date:** [April 13, 2012, 3:47am UTC](https://www.ruby-forum.com/t/help-with-convert-htaccess-to-nginx/218786/3 "2012-04-13T03:47:29Z")

</div>

I want convert htaccess to nginx, .htaccess file content:

# If the file is NOT the index.php file

RewriteEngine on  
RewriteCond %{REQUEST\_FILENAME} !index.php

# Hide all PHP files so none can be accessed by HTTP

RewriteRule (.\*).php$ index.php/$1

RewriteCond $1  
!^(index.php|nhototamsu|assets|cache|xd\_receiver.html|photo|ipanel|automap|xajax\_js|files|robots.txt|favicon.ico|ione.ico|(.\*).xml|ror.xml|tool|google6afb981101589049.html|googlec0d38cf2adbc25bc.html|widget|iradio\_admin|services|wsdl)

RewriteRule ^(.\*)$ index.php/$1 [QSA,L]

I convert to nginx:

if ($request\_filename !~ “index.php”) {  
rewrite /(._).php$ /index.php/$1;  
}  
if ($request\_uri !~  
"^(index.php|nhototamsu|assets|cache|xd\_receiver.html|photo|ipanel|automap|xajax\_js|files|robots.txt|favicon.ico|ione.ico|(._).xml|ror.xml|tool|google6afb981101589049.html|googlec0d38cf2adbc25bc.html|widget|iradio\_admin|services|wsdl)")  
{  
rewrite ^/(.\*)$ /index.php/$1 last;  
}

and nginx.conf file content:

worker\_processes 4;  
error\_log logs/error.log debug;  
events {  
worker\_connections 1024;  
}  
http {  
include mime.types;  
default\_type application/octet-stream;  
include /etc/nginx/conf.d/\*;  
sendfile on;  
server\_tokens off;  
keepalive\_timeout 15;

```
proxy_buffering off;

client_body_buffer_size 128K;
client_header_buffer_size 1k;
client_max_body_size 20m;
large_client_header_buffers 2 1k;

client_body_timeout 10;
client_header_timeout 10;
send_timeout 10;

gzip on;
gzip_comp_level 2;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/xml;
gzip_disable "MSIE [1-6]\.";
server {
    listen 80;
    server_name ione.net;

```

root /www/ione/virtual;  
if ($request\_filename !~ “index.php”) {  
rewrite /(._).php$ /index.php/$1;  
}  
if ($request\_uri !~  
"^(index.php|nhototamsu|assets|cache|xd\_receiver.html|photo|ipanel|automap|xajax\_js|files|robots.txt|favicon.ico|ione.ico|(._).xml|ror.xml|tool|google6afb981101589049.html|googlec0d38cf2adbc25bc.html|widget|iradio\_admin|services|wsdl)")  
{  
rewrite ^/(._)$ /index.php/$1 last;  
}  
location / {  
index index.php index.html index.htm;  
}  
error\_page 500 502 503 504 /50x.html;  
location = /50x.html {  
root html;  
}  
location ~_  
“.(js|ico|gif|jpg|png|css|html|htm|swf|htc|xml|bmp|cur)$” {  
add\_header Pragma “public-static”;  
add\_header Cache-Control “public-static”;  
expires 3M;  
access\_log off;  
log\_not\_found off;  
}  
location ~\* .php$ {  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME  
$document\_root$fastcgi\_script\_name;  
include fastcgi\_params;  
fastcgi\_param SCRIPT\_NAME $fastcgi\_script\_name;  
}  
location ~ /. {  
access\_log off;  
log\_not\_found off;  
deny all;  
}  
}  
}

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,225195,225276#msg-225276](http://forum.nginx.org/read.php?2,225195,225276#msg-225276)
