这样一个简单的问题,但htaccess和我从来没有沿着。
1.如果文件存在,则提供该文件。
1.如果URI只是/,并且如果index.html存在,则提供index.html
1.否则服务app.php
下面是.htaccess:
# Disable the directory processing, Apache 2.4
DirectoryIndex disabled xxx
RewriteEngine On
# Serve existing files
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# For / serve index.html if it exists
RewriteCond %{REQUEST_URI} ^/$
RewriteCond index.html -f
RewriteRule .? index.html [L]
# Otherwise use front controller
RewriteRule .? app.php [L]
字符串
如果我注解掉RewriteCond index.html -f行,只要index.html确实存在,它就可以工作。但是我也想检查index.php,所以我需要检查文件是否存在。如果没有别的,我想知道为什么张贴线不工作。
1条答案
按热度按时间tsm1rwdh1#
这应该可以工作:
字符串
请记住,
RewriteCond
与-f
或-d
需要完整的路径到文件或目录,这就是为什么你需要前缀的文件名与%{DOCUMENT_ROOT}/
。这里不需要转义点。