【问题标题】:.htaccess RewriteRule ^.*$ - [S=40] to Nginx [closed].htaccess RewriteRule ^.*$ - [S=40] 到 Nginx [关闭]
【发布时间】:2013-03-27 20:23:13
【问题描述】:

我在 appache 上设置了 https://github.com/lencioni/SLIR。它有一个 htaccess 文件并且运行良好。现在我已经搬到 Nginx 并希望 SLIR 以同样的方式工作。以下是我需要转换的内容。

# Prevent other scripts from interfering with SLIR
php_value auto_prepend_file none
php_value auto_append_file none

# Pretty URLs
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=40]
RewriteRule . index.php [L]
</IfModule>

# Prevent viewing of the error log file in its default location
<Files slir-error-log>
Order Deny,Allow
Deny from All
</Files>

我能够转换除以下行之外的所有内容

RewriteRule ^.*$ - [S=40]

有什么想法吗? 谢谢

【问题讨论】:

  • 这个问题最好在superuser.com上问

标签: .htaccess mod-rewrite nginx


【解决方案1】:

试试这个:

if (!-f $request_filename) { rewrite ^.*$ /index.php last; } # check for file
if (!-d $request_filename) { rewrite ^.*$ /index.php last; } # check for dir

EDIT 在我的服务器上检查 - 这一行适用于两者(目录和文件)

if (!-e $request_filename) { rewrite ^(.+)$ /index.php last; }

【讨论】:

    【解决方案2】:

    S 标志告诉 mod_rewrite 跳过一些以下规则(在您的情况下,它是 40)。您也可以将规则更改为:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    

    可能更容易转换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-11
      • 2016-02-10
      • 2021-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-15
      • 1970-01-01
      相关资源
      最近更新 更多