0

我需要为 nginx 服务器翻译一些 htaccess 规则,

我的 htaccess 是:

RewriteEngine On
RewriteBase /mysite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]

SetOutputFilter DEFLATE

<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
</ifModule>

我已经翻译了这部分

RewriteEngine On
RewriteBase /mysite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]

看起来像

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 ^/(.*)$ /mysite/index.php/$1 last;
}

可以吗?

然后我需要翻译 htaccess 的第二部分(如上所示)。

我怎么翻译呢?

4

1 回答 1

2
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 ^/(.*)$ /bitfungus/index.php/$1 last;
}

没事吧?`

不,它很丑。Nginx 不是 apache,您不应该在实际上不需要它们的地方使用重写(在大约 95% 的情况下,您不需要在 nginx 中进行重写)。

http://wiki.nginx.org/Pitfalls

正确的:

try_files $uri $uri/ /bitfungus/index.php$uri;
于 2012-11-27T19:17:10.633 回答