【发布时间】:2013-01-12 20:32:24
【问题描述】:
所以使用 apache 我有一个文件夹:
www.domain.com/folder/folder1/index.php?word=blahblah
我希望访问 www.domain.com/folder/folder1/blahblah 的用户在不更改 URL 的情况下重定向到上述 URL。
因此,我在文件夹/folder1/ 中有以下 .htaccess,它运行良好:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?word=$1
所以我想用 nginx 实现相同的功能,我使用了两个转换器: 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 错误报告“从上游读取响应标头时主脚本未知”或“没有这样的文件或目录”。
有人可以告诉我吗?
提前致谢!
【问题讨论】:
-
rewrite ^(.*(?![\.js|\.css])[^.]+)$ /index.php/$1 last;重写所有内容,只忽略 js 和 css 文件...我是带着这个问题来到这里的。
标签: url-rewriting nginx rewrite