您在這裡

為MediaWiki網站增加一個rss.xml展示新建頁面

James Qi 在 2017年3月5日 - 00:18 發表

  以前MediaWiki做的站點也留了rss.xml在.htaccess中指向一個網址https://%{HTTP_HOST}/api.php?hidebots=1&days=30&limit=1000&action=feedrecentchanges&feedformat=rss,但這個是“最近更新”,展示的是版本對比頁面鍊接,帶有很多&,在robots.txt中被屏蔽了,搜索引擎也不去爬取,我就改為/index.php?title=Special:NewPages&feed=rss&hideredirs=1&limit=500&namespace=0&tagfilter= 來展示“新建頁面”,另外就是把rss.xml不做成跳轉,而是固定的網址,實現辦法是先建一個rss.php:

<?php
/*
* rss.php replace rss.xml
* James Qi
* 2017-3-4 for MediaWiki
* modify .htaccess:
RewriteCond     %{REQUEST_URI}          ^\/rss\.xml$RewriteCond %{REQUEST_URI} ^\/rss\.xml$
RewriteRule ^(.*)$ /rss.php [L]
RewriteRule     ^(.*)$                  /rss.php [L]
*/
header("Content-Type: text/xml; charset=utf-8");
$server_name = $_SERVER['SERVER_NAME'];
$request_uri = "/index.php?title=Special:NewPages&feed=rss&hideredirs=1&limit=500&namespace=0&tagfilter=";
$rss = file_get_contents("https://$server_name$request_uri");
print $rss;
?>

  然後修改.htaccess:

RewriteCond %{REQUEST_URI} ^\/rss\.xml$
RewriteRule ^(.*)$ /rss.php [L]

  這樣用戶再訪問rss.xml時網址不會跳轉,而是依靠rss.php去讀取内容來這裡展示,例如: https://www.jamesqi.com/rss.xml

 

自由标簽:

發表新回應

Plain text

  • 不允許使用 HTML 標籤。
  • 自動將網址與電子郵件地址轉變為連結。
  • 自動斷行和分段。