# Nginx like Rewrite feature (.htaccess) doesn't seem to be working (Help)

**URL:** <https://www.ruby-forum.com/t/nginx-like-rewrite-feature-htaccess-doesnt-seem-to-be-working-help/239185>\
**Category:** NGINX\
**Created:** [February 16, 2014, 12:58pm UTC](https://www.ruby-forum.com/t/nginx-like-rewrite-feature-htaccess-doesnt-seem-to-be-working-help/239185 "2014-02-16T12:58:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [February 16, 2014, 12:58pm UTC](https://www.ruby-forum.com/t/nginx-like-rewrite-feature-htaccess-doesnt-seem-to-be-working-help/239185/1 "2014-02-16T12:58:27Z")

</div>

Good Morning.

I’m making a site and I want to make the link more usable so I used the  
Apache’s RewriteCond which is the one I more comfortable with. I know  
that  
there are a site or two that lets me convert and so I used them, the  
thing  
is that it doesn’t seem to be working neither of them.

this is what I have  
RewriteEngine On  
RewriteCond %(REQUEST\_FILENAME) !-d  
RewriteCond %(REQUEST\_FILENAME) !-f  
RewriteCond %(REQUEST\_FILENAME) !-i  
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

One gave me this ([http://winginx.com/htaccess](http://winginx.com/htaccess))

# nginx configuration

location / {  
rewrite ^(.+)$ /index.php?url=$1 break;  
}

and the other gave me this (  
[http://www.anilcetin.com/convert-apache-htaccess-to-nginx/](http://www.anilcetin.com/convert-apache-htaccess-to-nginx/))  
if (!-d %(REQUEST\_FILENAME)){  
set $rule\_0 1$rule\_0;  
}  
if (!-f %(REQUEST\_FILENAME)){  
set $rule\_0 2$rule\_0;  
}  
if (%(REQUEST\_FILENAME) !~ “-i”){  
set $rule\_0 3$rule\_0;  
}  
if ($rule\_0 = “321”){  
rewrite ^/(.+)$ /index.php?url=$1 last;  
}

My configuration is as follows  
[http://pastebin.com/DrA4aAii](http://pastebin.com/DrA4aAii)

My question is… Do I have to make an additional configuration to make  
it  
work or do I have to install something extra to make it work?

I forgot I’m using Debian 7.3 (Wheezy) and my nginx version is still  
1.2.1.  
Don’t know if it’s important or not but my MySQL client is MariaDB  
version  
5.5.35

Thanks

---

<div class="post-metadata">

**Author:** ![Paulo\_Ferreira](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bc8723/32.png) [@Paulo\_Ferreira](https://www.ruby-forum.com/u/Paulo_Ferreira)\
**Post date:** [February 17, 2014, 11:38am UTC](https://www.ruby-forum.com/t/nginx-like-rewrite-feature-htaccess-doesnt-seem-to-be-working-help/239185/2 "2014-02-17T11:38:03Z")

</div>

Hello!

On Sun, Feb 16, 2014 at 11:58:00AM +0000, Paulo Ferreira wrote:

> RewriteCond %(REQUEST\_FILENAME) !-d  
> RewriteCond %(REQUEST\_FILENAME) !-f  
> RewriteCond %(REQUEST\_FILENAME) !-i  
> RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

First of all, original rewrite rules you are trying to convert  
seem to be invalid. There is no “-i” test in Apache AFAIK.

You may want to rethink what you are trying to do, and do this in  
nginx - instead of trying to convert rules you think you need.

[…]

> My configuration is as follows  
> [http://pastebin.com/DrA4aAii](http://pastebin.com/DrA4aAii)
> 
> My question is… Do I have to make an additional configuration to make it  
> work or do I have to install something extra to make it work?

Your configuration already redirects everything which isn’t on the  
file system to /index.html, using the following rule:

```
location / {
    try_files $uri $uri/ /index.html;
}

```

What you likely need is to change /index.html to your php script.

See also this article for examples:

> **[Converting rewrite rules](http://nginx.org/en/docs/http/converting_rewrite_rules.html)**

–  
Maxim D.

> **[nginx](http://nginx.org/)**
