我希望根据目录中是否存在文件来使用 .htaccess 重定向到一个页面或另一个页面。
基本上,我需要将所有访问index.php的访问者发送到home.php页面(如果splash.php 不存在)或splash.php页面(如果splash.php 存在) strong> 存在于目录中,到目前为止我有这个...
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} index.php
RewriteCond %{DOCUMENT_ROOT}/splash.php -f
RewriteCond %{SCRIPT_FILENAME} !splash.php
RewriteRule ^.*$ /splash.php [L]
仅当我明确将 mysite.com/index.php 作为我的 URL 时,才会将访问者发送到 mysite.com/splash.php(如果它存在),如果仅使用 mysite.com URL,则不会工作。
我理解代码的前 3 行,但不理解 !splash.php -f 位(我是从在 SO 上找到的其他重定向代码中得到的)。
如果splash.php不存在,我如何重定向到home.php?
干杯!
最佳答案
试试这个规则。它应该在 mysite.com/index.php、mysite.com/或 mysite.com 上运行
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/splash.php -f
RewriteCond %{SCRIPT_FILENAME} !splash.php
RewriteRule ^(index\.php|/|)$ /splash.php [L]
关于php - .htaccess 如果文件存在则重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6306362/