在我的网站上,我只有两个页面“ index.php”和“ page.php”,无论我输入什么类型,都会重定向到localhost,例如,如果我转到localhost / randompage而不是重定向到404.html,则我转到localhost (即index.php)
这是我的conf:
server {
listen 80;
server_name localhost;
root html;
index index.php;
location / {
if ($request_uri !~* '\/|page\.php\?.*') {
return 404;
}
try_files $uri $uri/ /index.php;
}
error_page 404 /404.html;
location = /404.html {
root html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Run Code Online (Sandbox Code Playgroud)
我应该改变什么?
我有一个类似的问题。注释掉此行可解决此问题:
try_files $uri $uri/ /index.php;
Run Code Online (Sandbox Code Playgroud)
try_files检查给定的URI是否有效。如果不是,它将尝试查看给定的URI是否作为目录。失败的话,它重定向到/index.php。如果没有此行,它将提供指示的404文件error_page。
希望对您有用。
| 归档时间: |
|
| 查看次数: |
3989 次 |
| 最近记录: |