.htaccess重定向(重写)不使用真实文件路径重定向



我需要所有的url重定向到index.php,在那里我有一个处理url页面的路由器,所以如果有人输入了一个路径(甚至是真实路径),它会重定向到index.php:

Options -Indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^inmomarco.com$
RewriteRule (.*) http://www.inmomarco.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

它不适用于真正的路径,如果我在/pages/file.php中有一个文件,并且我试图导航到它,那么它不会适用于上述规则,为什么?

在index.php中,我获取uri并对其进行转义:

$url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
// some security checks
// an array with the uri as keys and page names as values

在main.php中,我包括页面

$include = '/404';
if (array_key_exists($url, $includes)) {
    $include = $url;
}
include($includes[$include]);

这工作正常,问题是index.php没有解析的真实文件路径(在url栏中)。这应该发生吗?或者有什么我能做的吗?

此外,如果我尝试导航到/index.php,它将显示我的404页面,但如果我转到另一个文件,它会显示它,而index.php不会完成他的工作。。。

.htaccess:中使用

RewriteEngine On
RewriteCond %{HTTP_HOST} ^inmomarco.com$
RewriteRule (.*) http://www.inmomarco.com/$1 [R=301,L]
RewriteBase /
RewriteRule !^index.php$ /index.php [L]

因为-f-d测试现有文件或目录

最新更新