我迁移我的服务器从阿帕奇Nginx的,并有一个非常简单的的.htaccess
规则:
I'm migrating my server from Apache to Nginx and have this very simple .htaccess
rule:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
这背后的想法是把每一个请求到前端控制器(的index.php
)。我试图与Nginx的这样做。我用了一个在线转换器,使这个Nginx的位置块:
The idea behind it is to direct every request to a front controller (index.php
). I'm trying to do the same with Nginx. I used an online converter to make this Nginx location block:
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
}
但是当我将它添加到我的网站的配置Nginx的刚吐出来的是PHP文件作为下载源$ C $ C。作为参考,这里是整个配置文件:
but when I add it to my site's configuration Nginx just spits out the source code of the PHP file as a download. For reference, here's the entire configuration file:
http://pastebin.com/tyKtM1iB
我知道PHP的作品,因为如果我删除的位置块,并以文件< PHP的phpinfo();
它正常工作
I know PHP works, as if I remove the location block and make a file with <?php phpinfo();
it works correctly.
任何帮助将是AP preciated。
Any help would be appreciated.
推荐答案
这就是我的路线一切index.php文件,包括子目录的请求,HTTP ARGS,等。
This is how I route EVERYTHING to index.php, including sub-directory requests, HTTP args, ect.
location / {
try_files $uri $uri/ /index.php?$args; #if doesn't exist, send it to index.php
}
location ~ .php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
# By all means use a different server for the fcgi processes if you need to
fastcgi_pass 127.0.0.1:9000;
}
因此,例如,这些被发送到index.php的:
So for example, these get sent to index.php:
http://foo.bar/something/
http://foo.bar/something/?something=1
虽然这些直接进入文件
While these go directly to files
http://foo.bar/someotherphp.php
https://p.xsw88.cn/allimgs/daicuo/20230902/207.png.jpg
相关推荐
最新文章