[杂文]修改文章永久链接的后续处理
续上回 [站务]本站文章永久链接变更
在typecho的安装目下建立url.php
代码如下:
<?php
require_once 'config.inc.php';
$db = Typecho_Db::get();
if ($_GET['q']) {
$q = $_GET['q'];
$cid = $db->fetchRow($db->select('cid')->from('table.contents')->where('slug = ?', $q))['cid'];
if ($cid) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: /' . $cid . '.html');
} else {
header('HTTP/1.1 404 Not Found');
}
}
然后伪静态 Apache代码则如下
RewriteRule archives/([^/]+)\.html? url.php?q=$1 [L]
将上述Apache 在伪静态规则后方追加
这行意思仅应用于 用别名作为永久链接的时候 其他别名以此类推
如果是nginx 则 在伪静态规则前方追加
rewrite /archives/([^/]+)\.html? /url.php?q=$1 last;
本文基于《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
文章链接:https://yukimax.org/18-110901.html (转载时请注明本文出处及文章链接)
此处评论已关闭