Hi i m having issue while setting htaccess rule in nginx. My htaccess is :

htaccess rules are:

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

I have converted it like this:

if (!-f $request_filename){
        set $rule_0 1$rule_0;
if (!-d $request_filename){
        set $rule_0 2$rule_0;
if ($rule_0 = "21"){
        rewrite /.* /index.php/$request_uri last;

I have read that if is evil for nginx but i dont understand these rules. My application which i am trying to setup is:


Now rule is useful when we try to access admin area. We access it by writing /administrator in url and the rules takes this as input for index.php and we login to that. But after applying this rule i see in log that error 404 is coming. Let me mention that nginx vhost is reloading properly after this rule and i have added this rule in server area and loxation area also but nog working

  • 1
    Don't use online apache->nginx conversion tools. They produce junk config like that in the question. You only need try_files for what is asked.
    – AD7six
    Mar 16, 2015 at 7:28

2 Answers 2


You want to look into the location blocks http://nginx.org/en/docs/http/ngx_http_core_module.html#location and the try_files directives http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files

For example, if you look at the wordpress blog (a fairly comprehensive example) http://wiki.nginx.org/WordPress you'll see this:

 location /wordpress {
    try_files $uri $uri/ /wordpress/index.php?$args;

 location ~ \.php$ {
    fastcgi_split_path_info ^(/wordpress)(/.*)$;

which is saying "try the file directly in /wordpress, otherwise pass it across to index.php for processing".


Thank you so much for giving idea about try files. I worked on it and entered this block in location: try_files $uri $uri/ /index.php;

It worked and not i can access http://my.url.com/administrator

Further the below mentioned stack link is best for understanding try files which helped me as well.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .