Score:0

Nginx rewrite rule return php in plain text

cn flag

I have an Apache Configuration file that contains many rewrite rules.

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://website.uri/$1 [R,L]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^p/(.*)$ index.php?rqt=page/index/url/$1 [NC,L]
RewriteRule ^(.*)$ index.php?rqt=$1 [NC,L,QSA]
<FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
  </IfModule>
</FilesMatch>

After a switch to Nginx, I have tried to convert these rules, here is the result:

    location ~ ^(.*)$ { }

    location / {
        rewrite ^(.*)$ https://website.uri/$1 redirect;
        if (-e $request_filename) {
            rewrite ^/p/(.*)$ /index.php?rqt=page/index/url/$1 break;
        }
        rewrite ^(.*)$ /index.php?rqt=$1 break;
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php-fpm.sock;
    }

The problem is that now, my PHP code does not execute anymore and is directly displayed in text format.

How can I fix this problem?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.