PHP的包含语句无法访问.htaccess

时间:2019-07-05 21:16:43

标签: php .htaccess

当通过在根文件夹中添加.htaccess来使用Pretty URL时,我的<a href="">链接当然不需要.php文件扩展名。但是,当我使用PHP requireinclude时,它会引发错误,并且似乎没有使用.htaccess来添加必要的.php,要求我将.php添加到这些语句中。 / p>

.htaccess

# Redirect everything that doesn't match a directory or file to index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

相关的.php文件:

<!DOCTYPE html>
<head></head>
<body>
    <?php require "../Resources/nav.php";?>
        // Main Content
    <?php require "../Resources/footer.php";?>
</body>

有人知道为什么这些语句不使用.htaccess吗?仅仅是需要包括文件扩展名,还是有办法强迫他们使用.htaccess?

1 个答案:

答案 0 :(得分:2)

Apache Web服务器对网络上的请求做出反应。 RewriteRules仅适用于这些请求。

PHP requireincludefile_get_contents等功能通常访问本地存储,而不是通过网络向Apache发送HTTP请求。

虽然可以将file_get_contents与URL结合使用,并且有时有用,但是在您的用例中,您必须添加.php扩展名以解决正确的本地文件。

相关问题