请帮助我将zcart应用程序的htaccess规则转换为nginx配置。请参阅下面的htaccess。
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
谢谢
答案 0 :(得分:0)
假设您已经配置了config的FastCGI部分,请尝试:
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
可以转换为nginx配置,
location ~ ^(.+)/$ {
if (!-d $request_filename) {
return 301 $1;
}
# else this is a directory, will be processed via index file in this directory by default
}
或(相同的结果)
location ~ ^(.+)/$ {
if (!-d $request_filename) {
rewrite ^(.*)/$ $1 permanent;
}
# else this is a directory, will be processed via index file in this directory by default
}
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
将由主try_files
块中的单个location
指令处理:
location / {
try_files $uri $uri/ /index.php;
}
最后,
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
在nginx.conf
中不需要任何其他配置,因为在设置HTTP $_SERVER[HTTP_AUTHORIZATION]
标头时,$_SERVER
变量将自动附加到Authorization
数组中(如果您的php-fpm配置正确)。