你好,我有一个 LEMP 服务器,我使用了下面的 .htaccess 文件将空目录重定向到 index.php,但问题是它没有执行 index.php 中的代码,它只是打印了 Array()
.htaccess 文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?path=$1 [NC,L,QSA]
nginx 服务器配置
server {
listen 80;
root /storage/html/stream;
index index.php index.html index.htm index.nginx-debian.html;
server_name stream.example.com;
include snippets/phpmyadmin.conf;
location / {
try_files $uri $uri/ =404 /rest/index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
phpMyAdmin 位置,我已将其包含在我的服务器块中
location /phpmyadmin {
root /storage/html/stream/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /storage/html/stream/;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~ ^/phpmyadmin/(doc|sql|setup)/ {
deny all;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /storage/html/stream/;
}
}
这是我的 index.php 文件
<?php
print_r($_GET);
require_once("app/config.php");
require_once("app/core/core.php");
require_once( "app/core/router.php");
这是输出http://stream.example.com/rest/?path=video/server
Array
(
[path] => video/server
)
{"authorization":0,"error":1,"result":0,"message":"Token is invalid."}
这是输出http://stream.example.com/rest/video/server
Array ( )
但它们都应该给我这个输出:
Array ( [path] => video/server/ )
有人能帮我解决这个问题吗?
答案1
最后,我将index.php
文件传输到服务器的根目录,并通过添加index.php?$uri
到我的try_files
和 YeaP 解决了这个问题,.htaccess 文件根本不起作用
但是我有一个问题,如果我想将我的放在index.php
子目录中,我该怎么做?
顺便说一下,这种配置的名称是前端控制器你可以通过这个名字来搜索
谢谢