htaccess:如何只允许访问一个文件,否则请求 index.php?

htaccess: How to allow access only to one file, otherwise request index.php?

如何只允许访问一个文件,否则使用 .htaccess 请求 index.php

我只需要允许访问文件 update.php。如果不是这个文件,那么直接访问index.php。 我试过这段代码:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} ^update\.php$ [NC]
    RewriteRule . index.php [L]
</IfModule>

但它允许访问所有文件。我不知道为什么。 希望得到您的帮助!

根据您显示的示例,您能否尝试以下操作。请确保在测试您的 URL 之前清除您的浏览器缓存。

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(!?update\.php).*$ - [NC,F,L]

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

就这样吧:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/update\.php$ [NC]
RewriteRule ^ index.php [L]