doule0941 2019-04-16 21:54
浏览 478

允许在vue.js Web应用程序中动态创建sitemap.xml

I have a Vue.JS single page application with a PHP back-end running on apache. The app is running fine, using the vue.js routing to navigate between pages.

I want to dynamically create an XML sitemap based on records in a database (each record has it's own page). I have a .php file which generates the XML and returns text/xml.

<?php 

    header("Content-type: text/xml");
?>

<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
    <url>
        <loc>https://myapp.com/</loc>
        <priority>1.00</priority>
    </url>

    <?php
          ###### Code for calling the DB
     ?>
</urlset>

In my .htaccess file, I'm redirecting sitemap.xml to my sitemap.php page.

<IfModule mod_rewrite.c>

  RewriteEngine on
  RewriteRule ^sitemap\.xml$ /php/sitemap.php [L]
  RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?shortName=$1 [NC,L]

</IfModule>

However, the vue.js router is intercepting the request and displaying my 404 page.

const routes = [
    // home
    {name: 'home',path: '/',component: Home},

    // all my other routes here

    // 404 catch-all
    { path: '*', component: NotFound}
]

Is there a way to ignore certain routes in the vue.js router? Or am I going about this the wrong way?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 5037端口被adb自己占了
    • ¥15 python:excel数据写入多个对应word文档
    • ¥60 全一数分解素因子和素数循环节位数
    • ¥15 ffmpeg如何安装到虚拟环境
    • ¥188 寻找能做王者评分提取的
    • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
    • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
    • ¥15 写论文,需要数据支撑
    • ¥15 identifier of an instance of 类 was altered from xx to xx错误
    • ¥100 反编译微信小游戏求指导