gpt4 book ai didi

php - Laravel 5 nginx domain.com/index.php 和 domain.com/both 工作。如何重定向/index.php?

转载 作者:可可西里 更新时间:2023-10-31 23:46:49 25 4
gpt4 key购买 nike

在 raspberry pi 2 上安装了 nginx 和 php 5.6。工作出色,但我的页面仍然从 xyz.com/index.php/whatever(错误)以及 xyz.com/whatever(完美)加载。我不希望/index.php 加载我的主页。我希望它重定向到/没有 index.php。这也适用于所有子文件夹。我究竟做错了什么??这是我构建的第一台服务器,因此我们将不胜感激。谢谢。

站点可用配置:

server {
root /data/something.com/www/something/public;
index index.php index.html index.htm;
server_name something.com.local;

# Logging
error_log /data/something.com/logs/error.log;
access_log /data/something.com/logs/access.log;

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

# Disallow access to hidden files
location ~ /\. {
deny all;
}

# Some locations will never contain PHP files, handle it in the server
location ~ ^/(robots.txt|favicon.ico)(/|$) {
try_files $uri =404;
}

# Pretty urls no /index.php (THIS IS WORKING...BUT /index.php is still accessible?)
location / {
try_files $uri $uri/ /index.php?$query_string;
}

# Remove trailing slash to please routing system.
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}

error_page 404 /index.php;

sendfile off;

# PHP
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

# We don't need .ht files with nginx.
location ~ /\.ht {
deny all;
}
}

最佳答案

nginx redirect loop, remove index.php from url 中所述类似于 Remove index.php from Joomla! URLs with NGINX ,当从 index.php 重定向时,你必须使用一个特殊的技巧来避免重定向循环:

index index.php index.html index.htm;
if ($request_uri ~ "^/(.*)(?<=/)index\.php[/?]?((?<=[/?]).*)?$") { return 301 /$1$2; }

关于php - Laravel 5 nginx domain.com/index.php 和 domain.com/both 工作。如何重定向/index.php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32529111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com