所以用Apache我有一个文件夹:
www.domain.com/folder/folder1/index.php?word=blahblah
我希望访问www.domain.com/folder/folder1/blahblah的用户可以redirect到上面的URL,而不需要更改URL。
因此,我有以下.htaccess文件夹/ folder1 /完美的作品:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ index.php?word=$1
所以我想实现与nginx相同的function,我使用了两个转换器: http : //www.anilcetin.com/convert-apache-htaccess-to-nginx/结果在:
if (!-f $request_filename){ set $rule_0 1$rule_0; } if (!-d $request_filename){ set $rule_0 2$rule_0; } if ($rule_0 = "21"){ rewrite ^/(.+)$ /index.php?word=$1; }
和http://winginx.com/htaccess结果在:
if (!-e $request_filename){ rewrite ^(.+)$ /index.php?word=$1; }
现在,我尝试了两个,但都没有工作。 我试图插入他们
location / { }
或中
location /folder/folder1 { }
或中
location ~ \.php$ { }
在所有地点我得到一个404错误
nginx错误报告“读取来自上游的响应头时的主要脚本未知”或“没有这样的文件或目录”。
有人能够赐教吗?
提前致谢!
首先,不要使用if
。 如果是邪恶 – > http://wiki.nginx.org/IfIsEvil
您可以通过使用以下重写规则来完成此操作。
rewrite ^/folder/folder1/(.*)$ /folder/folder1/index.php?word=$1 last;
将此重写规则放在location / {}
块的上方