# Help with convert .htaccess to nginx :(

**URL:** <https://www.ruby-forum.com/t/help-with-convert-htaccess-to-nginx/213264>\
**Category:** NGINX\
**Created:** [October 28, 2011, 5:26am UTC](https://www.ruby-forum.com/t/help-with-convert-htaccess-to-nginx/213264 "2011-10-28T05:26:55Z")\
**Posts on this page:** 5\
**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:** [October 28, 2011, 5:26am UTC](https://www.ruby-forum.com/t/help-with-convert-htaccess-to-nginx/213264/1 "2011-10-28T05:26:55Z")

</div>

Hi guys,

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:

Options +FollowSymLinks +ExecCGI

AddDefaultCharset utf-8

 Order deny,allow Deny from all 

\<FilesMatch “pre\_.+.php”\>  
Order deny,allow  
Deny from all

 RewriteEngine On
# uncomment the following line, if you are having trouble

# getting no\_script\_name to work

#RewriteBase /

# we skip all files with .something

RewriteCond %{REQUEST\_URI} ..+$  
RewriteCond %{REQUEST\_URI} !.html$  
RewriteRule .\* - [L]

# we check if the .html version is here (caching)

RewriteRule ^$ index.html [QSA]  
RewriteRule ^([^.]+)$ $1.html [QSA]  
RewriteCond %{REQUEST\_FILENAME} !-f

# no, so we redirect to our front web controller

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

I’ve tried to convert to:  
rewrite ^ index.php last;

But it didn’t work.

When I access [http://myurl.com/installer.php](http://myurl.com/installer.php) nginx could display the  
page correctly, but when I clicked Next button, it said: “404 Not Found”  
(new URL: [http://myurl.com/installer.php/step1](http://myurl.com/installer.php/step1))

Anyone has any solution for this?

Thank in advanced,  
Giang

Posted at Nginx Forum:

> **[Help with convert .htaccess to nginx :(](https://forum.nginx.org/read.php?2,217447,217447#msg-217447)**
>
> Hi guys, 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: Options +FollowSymLinks +ExecCGI AddDefaultCharset utf-8 \<IfModule mod\_authz\_host.c\>

---

<div class="post-metadata">

**Author:** ![Giang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Giang](https://www.ruby-forum.com/u/Giang)\
**Post date:** [October 28, 2011, 5:35am UTC](https://www.ruby-forum.com/t/help-with-convert-htaccess-to-nginx/213264/2 "2011-10-28T05:35:33Z")

</div>

On Fri, Oct 28, 2011 at 10:26 AM, Giang [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<FilesMatch “.(lock|conf)$”\>  
> Order deny,allow  
> Deny from all

location ~ .(lock|conf)$ { deny all; }

> \<FilesMatch “pre\_.+.php”\>  
> Order deny,allow  
> Deny from all

location ~ pre\_.+.php$ { deny all; }

> RewriteCond %{REQUEST\_URI} !.html$

location ~ /[^.]+$ {  
try\_files $uri $uri/ $uri.html /index.php;  
}

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![Giang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Giang](https://www.ruby-forum.com/u/Giang)\
**Post date:** [October 28, 2011, 5:37am UTC](https://www.ruby-forum.com/t/help-with-convert-htaccess-to-nginx/213264/3 "2011-10-28T05:37:25Z")

</div>

On Fri, Oct 28, 2011 at 10:26 AM, Giang [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> When I access [http://myurl.com/installer.php](http://myurl.com/installer.php) nginx could display the  
> page correctly, but when I clicked Next button, it said: “404 Not Found”  
> (new URL: [http://myurl.com/installer.php/step1](http://myurl.com/installer.php/step1))

As for this one, you need something with fastcgi\_split\_path. I’m not  
really familiar but I think something like this:

location ~ .php(/.+)$ {  
fastcgi\_split\_path …  
…  
}

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![Giang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Giang](https://www.ruby-forum.com/u/Giang)\
**Post date:** [October 28, 2011, 5:58am UTC](https://www.ruby-forum.com/t/help-with-convert-htaccess-to-nginx/213264/4 "2011-10-28T05:58:23Z")

</div>

Thank you. I’ve changed as you suggested, but it still hasn’t worked.  
When I clicked Next button, it just reloaded the page.

Here is my new nginx configuration file content:  
location ~ .(lock|conf)$ { deny all; }  
location ~ pre\_.+.php$ { deny all; }  
location ~ /[^.]+$ {  
try\_files $uri $uri/ $uri.html /index.php;  
}  
location ~ .php(/.+)$ {  
fastcgi\_split\_path\_info ^((?U).+.php)(/?.+)$;  
fastcgi\_param SCRIPT\_FILENAME  
/var/www/siwapp/web$fastcgi\_script\_name;  
fastcgi\_param PATH\_INFO $fastcgi\_path\_info;  
fastcgi\_param PATH\_TRANSLATED $document\_root$fastcgi\_path\_info;  
}

Posted at Nginx Forum:

> **[Re: Help with convert .htaccess to nginx :(](https://forum.nginx.org/read.php?2,217447,217451#msg-217451)**
>
> Hi guys, 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: Options +FollowSymLinks +ExecCGI AddDefaultCharset utf-8 \<IfModule mod\_authz\_host.c\>

---

<div class="post-metadata">

**Author:** ![Giang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Giang](https://www.ruby-forum.com/u/Giang)\
**Post date:** [March 21, 2012, 8:55pm UTC](https://www.ruby-forum.com/t/help-with-convert-htaccess-to-nginx/213264/5 "2012-03-21T20:55:04Z")

</div>

I realize I’m responding to an old thread here, but thought I would post  
the configuration that I used to get this working:

location / {  
try\_files $uri $uri/ /index.php$uri?$args;  
}

location = /robots.txt { access\_log off; log\_not\_found off; }  
location = /favicon.ico { access\_log off; log\_not\_found off; }  
location ~ /. {access\_log off; log\_not\_found off; deny all; }  
location ~ .(lock|conf)$ { access\_log off; log\_not\_found off; deny  
all; }  
location ~ pre\_.+.php { access\_log off; log\_not\_found off; deny all;  
}  
location = /test\_rewrite1.txt { rewrite ^ /test\_rewrite2.txt; }

location /js/i18n {  
autoindex on;  
}

location ~ .php {  
include fastcgi.conf;  
fastcgi\_split\_path\_info ^((?U).+.php)(/?.+)$;  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;  
fastcgi\_param PATH\_INFO $fastcgi\_path\_info;  
fastcgi\_param PATH\_TRANSLATED $document\_root$fastcgi\_path\_info;  
fastcgi\_pass unix:/tmp/php-fpm.sock;  
}

Posted at Nginx Forum:

> **[Re: Help with convert .htaccess to nginx :(](https://forum.nginx.org/read.php?2,217447,224195#msg-224195)**
>
> Hi guys, 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: Options +FollowSymLinks +ExecCGI AddDefaultCharset utf-8 \<IfModule mod\_authz\_host.c\>
