1

I'm trying to move my website from Apache to Nginx. My website is structured like this :

  • www_root
    • public
    • other folders

All requests are redirected from www_root to public folder with an .htaccess that contains :

RewriteRule    ^$   public/    [L]
RewriteRule    (.*) public/$1    [L]

In the public folder, all requests are redirected to single entry point index.php with this .htaccess :

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]

At the moment my server block is like that :

server {
    server_name domain.com www.domain.com;
    root /var/www/domain.com/htdocs/public;

    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }
}

So I only cam view the desired page by adding the query string. E.g. http://www.domain.com/?page=the/page/to/see

How can I achieve this with Nginx ? I tried many solutions but without success.

Thank you for your help !

0

You must log in to answer this question.

Browse other questions tagged .