【发布时间】:2021-06-29 15:42:12
【问题描述】:
我需要帮助来在 nginx 服务器上配置我的网站。早些时候我使用的是 apache,所以我使用 htaccess 在 index.php 上重定向。但我才知道 nginx 不支持 htaccess。我是 nginx 服务器的新手。让我通过例子更清楚地说明。
当我使用 apache 时,我的 htaccess 如下所示-
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
我现在需要在 nginx 服务器上做同样的事情。请任何人建议我如何做到这一点。我试图自己弄清楚并尝试了很多东西,但没有任何效果,例如-
我试过了-
location / {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /index.php;
}
我也尝试了这里建议的解决方案: How to enable URL rewrite in Ubuntu, nGinx and codeigniter?
location ~* \.php$ {
fastcgi_pass unix:/run/php/php5.6-fpm.sock;
root /var/www/html/;
try_files $uri =404;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
我的要求是重写所有这些网址:
https://example.com/xyz
https://example.com/abc
https://example.com/pqr
收件人
https://example.com/index.php
我的文件夹结构- folder-structer.png
提前致谢。
【问题讨论】:
标签: php .htaccess nginx redirect mod-rewrite