.htaccess到nginx重写规则

时间:2012-01-25 15:06:11

标签: .htaccess nginx

我想转换一个与nginx一起使用的简单.htaccess文件(规则)。我尝试在googleit之后访问一个在线工具,但该网站已关闭。所以,如果有人帮忙,我会很感激。谢谢。这是我的.htaccess文件:

选项+ FollowSymLinks + ExecCGI

<IfModule mod_rewrite.c>
  RewriteEngine On

  # we skip all files with .something
  RewriteCond %{REQUEST_URI} \..+$
  RewriteCond %{REQUEST_URI} !\.html$
  RewriteRule .* - [L]

  # we check if the .html version is here (caching)
  RewriteRule ^$ index.html [QSA]
  RewriteRule ^([^.]+)$ $1.html [QSA]
  RewriteCond %{REQUEST_FILENAME} !-f

  # no, so we redirect to our front web controller
  RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

2 个答案:

答案 0 :(得分:1)

请尝试以下规则:

# Deny all files that started with dot
location ~ /\. {
        deny all;
}
# Try $uri - is file, $uri/ - is dir, index.html - caching, $uri.html caching, index.php -last
location / {
        try_files $uri $uri/ index.html $uri.html index.php;
}

答案 1 :(得分:0)

请尝试以下规则:

# nginx configuration

location ~ \.html$ {
}

location / {
  if ($request_uri ~ "\..+$"){
    rewrite ^/$ /index.html;
  }
  rewrite ^/([^.]+)$ /$1.html;
  if (!-e $request_filename){
    rewrite ^(.*)$ /index.php break;
  }
}