首页 > 解决方案 > php mvc 动态站点地图

问题描述

你好我正在使用 php mvc 模型。我创建了一个站点地图。路径:localhost / sitemap 无论我在 .htaccess 中做了什么,我都无法转换 sitemap.xml。我无法解决问题。

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
<IfModule mod_mime.c>
  AddType text/javascript js mjs
</IfModule>

RewriteRule ^([a-zA-Z0-9-_/]+)$ index.php [QSA]

#Sitemap
RewriteRule ^sitemap.xml$ sitemap.php [NC,L]

索引.php

$routeExplode = explode('?', $_SERVER['REQUEST_URI']);
$route = array_values(array_filter(explode('/', $routeExplode[0])));

require controller(route(0));

初始化文件

spl_autoload_register(function ($class_name) {

    // Define an array of directories in the order of their priority to iterate through.
    $dirs = array(
        __DIR__ . '/classes/', // Core classes example
    );

    foreach ($dirs as $dir) {
        if (file_exists($dir . strtolower($class_name) . '.php')) {
            require_once($dir . strtolower($class_name) . '.php');
        }
    }
});

标签: php.htaccess

解决方案


您可能从控件将其配置为 * .php,因此 index.php 中的更改解决了您的问题。

RewriteRule ^sitemap\.xml$ sitemap [L]

指数

if (route(0) === "sitemap.xml") {
    require_once '....';
}

推荐阅读