php - 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,因此 index.php 中的更改解决了您的问题。
RewriteRule ^sitemap\.xml$ sitemap [L]
指数
if (route(0) === "sitemap.xml") {
require_once '....';
}
推荐阅读
- incompatibletypeerror - 不兼容的操作数类型 String[] 到 int
- maven - Maven - 编译 mule 应用程序 AtnRun 插件后,目标目录中的包中的路径 xml 文件是什么?
- python - 如何阻止列表成员消息
- php - 覆盖 Laravel 7 中的默认 Auth 路由
- unity3d - WebGL 游戏不会响应键盘输入。它在 Unity 中完美运行。我怎样才能让它在浏览器中工作?
- python - 将字符串类型绘制为 x 轴标记
- html - 用html和css制作表格,但没有对齐
- excel - 无效的采购或论证
- mysql - 无法将包含 json 对象列表的字符串类型的 db 字段扫描到 Golang Struct
- encoding - 将 ffmpeg 与 vidstab 和编码 2 通道一起使用的更好方法