如何保留 xml 扩展名但从 php 文件加载

dan*_*y89 0 php .htaccess

请求page1时是否可以从page2加载资源?

例如我有网址: http: //site.ru/sitemap.xml

我想从页面加载数据:http://site.ru/index.php? route=feed/google_sitemap 但我也想保留 URL http://site.ru/sitemap.xml

zan*_*war 5

如果您希望保留扩展名,则需要使用 mod_rewrite (Apache) 重写 URL .xml

.htaccess

RewriteEngine On
RewriteRule ^sitemap.xml$   sitemap.php
Run Code Online (Sandbox Code Playgroud)

站点地图.php

<?php
header ("Content-Type:text/xml");
echo file_get_contents("http://site.ru/index.php?route=feed/google_sitemap")
?>
Run Code Online (Sandbox Code Playgroud)

或者如果您想避免将 sitemap.php 全部制作在一起

RewriteEngine On
RewriteRule ^sitemap.xml$   index.php?route=feed/google_sitemap
Run Code Online (Sandbox Code Playgroud)