将.htaccess转换为nginx(mod_rewrite)

时间:2013-02-17 23:03:28

标签: apache .htaccess mod-rewrite nginx

我的apache有以下.htaccess文件:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks    
# Options +SymLinksIfOwnerMatch
  RewriteEngine On
  RewriteBase /
  RewriteRule ^$          index.php       [L]
  RewriteCond %{REQUEST_FILENAME}         !-f
  RewriteCond %{REQUEST_FILENAME}         !-d
  RewriteRule (.*)        index.php?page=$1  [QSA,L]
</IfModule>

突然间,我不得不将我的网络服务器更改为nginx,我不知道为什么,但mod重写不起作用。

我使用在线'转换器'来转换它,所以我有以下内容:

location / {
  rewrite ^/$ /         index.php       break;
  if ($request_filename ~         !-f){
    rewrite ^(.*)$ /       index.php?page=$1   break;
  }
}

你能帮我解决什么问题吗?

提前致谢, 马塞尔

2 个答案:

答案 0 :(得分:18)

http://blog.martinfjordvald.com/2011/02/nginx-primer-2-from-apache-to-nginx/ 一切都在里面。不再有.htaccess,没有更复杂的规则使用try_files。

编辑:如果不明显,请不要相信在线转换器。

答案 1 :(得分:0)

$ sudo vim / etc / nginx / sites-available / default

  location / {
        try_files $uri $uri/ =404;
    }

location / {
    try_files $uri $uri/ /index.php?$args;
}
相关问题