简体   繁体   中英

Problem in converting .htaccess mod_rewrite to nginx directive

I have great difficulties converting this apache rewrite rule to nginx:

<IfModule mod_rewrite.c>
    RewriteEngine On
    Options +FollowSymLinks
    Options -Indexes

    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule . index.php [L,QSA]
</IfModule>

What I've tried A:

 location  / {
        try_files $uri $uri/ index.php$is_args$args;
    }

B:

 location  / {
        try_files $uri $uri/ index.phps$args;
    }

However A does give 404 error for any /path and B works for /path/to/somewhere but does downloads /path .

here is my complete vhost:

server {
        listen 8000;
        root /var/www/myphpapp;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name localhost;
        #autoindex off;

        location / {
                try_files $uri $uri/ index.php$is_args$args; #A
                #try_files $uri $uri/ /index.php?$args; #B

        }


        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}

So I'm wondering what is the correct nginx directive?

I think there is a typo. You missed a slash:

         try_files $uri $uri/ /index.php$is_args$args;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM