我在Apache下面的.htaccess文件redirect所有请求到app/index.php有或没有GET参数。 我刚刚安装了NGINX,我的应用程序将无法运行。 任何人都可以协助在NGINX中复制相同的function吗? 谢谢。
RewriteEngine on Options -Indexes RewriteRule ^$ app/ [L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.+)$ app/index.php?url=$1 [QSA,L]
使用重写模块 。 像这样的东西应该这样做:
location / { autoindex off; rewrite ^/$ app/ last; if (!-e $request_filename) { rewrite ^/(.*)$ app/index.php?url=$1; } }
对于大多数configuration,不需要使用重写模块。
Apache的重写规则意味着:
RewriteRule ^$ app/ [L] – 发送url /到应用程序目录 RewriteCond %{REQUEST_FILENAME} !-d – RewriteCond %{REQUEST_FILENAME} !-d – 如果请求不是目录 RewriteCond %{REQUEST_FILENAME} !-f – RewriteCond %{REQUEST_FILENAME} !-f – 如果请求不是文件 RewriteCond %{REQUEST_FILENAME} !-l – RewriteCond %{REQUEST_FILENAME} !-l – 如果请求不是符号链接 app/index.php?url=$1 在nginx中相当于:
# No automatic directory listings autoindex off; # Send the root url to the app dir index index.php; rewrite ^/$ app/ last; # check if the url matches a file, directory and if not send to app/index.php try_files $uri $uri/ app/index.php?url=$uri;
检查符号链接是多余的,因为符号链接也是文件或目录。