我已经尝试了两天将 .htaccess 转换为 nginx 重写原始文件如下所示:
# Turn on URL rewriting
RewriteEngine On
RewriteBase //
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# List of files in subdirectories will not be displayed in the browser
Options -Indexes
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
AddDefaultCharset utf-8
AddCharset UTF-8 .htm …
Run Code Online (Sandbox Code Playgroud) 我在将 .htaccess 文件转换为 nginx 时遇到问题。我有 3 个 .htaccess 文件。第一个 .htaccess 文件位于文档根目录中,如下所示:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^img-(.*)\.html img.php?id=$1 [L]
RewriteRule ^slide-(.*)\.html slider.php?id=$1 [L]
RewriteRule ^page-(.*)\.html page.php?name=$1 [L]
RewriteRule ^contact\.html$ contact.php [QSA,L,NC]
Run Code Online (Sandbox Code Playgroud)
第二个 .htaccess 文件位于名为 upload 的文件夹中:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?foo\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ nohotlink.gif [L]
<Files ~ "\.(php|sql|php3|php4|phtml|pl|py|jsp|asp|htm|shtml|sh|cgi)$">
order allow,deny
deny from all
</Files>
Run Code Online (Sandbox Code Playgroud)
第三个也是最后一个 .htaccess 文件位于名为“small”的上传文件夹的子目录中:
RewriteEngine Off
Run Code Online (Sandbox Code Playgroud)
现在我在 /etc/nginx 中创建了一个文件夹,名为 includes 并使用这些重写规则制作了 3 个单独的 .access 文件:
对于位于文档根目录中的第一个 .htaccess 文件,我在 /etc/nginx/includes 中创建了一个名为 root.access 的文件。在这个文件中,我有:
# …
Run Code Online (Sandbox Code Playgroud)