我正在尝试将一些 apache 规则转换为 nginx。
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
但是,到目前为止我使用的是这个 Nginx 配置。
server {
listen 80;
server_name example.com;
root /path/to/your/document/root;
# Serve files from the public directory if they have an extension
location ~* \.\w+$ {
rewrite ^(.*)$ /public/$1 break;
}
# Route all other requests to server.php
location / {
try_files $uri $uri/ /server.php;
}
}
它不工作
我该如何修复它