教程中心伪静态规则
李元波 发布于
阅读:18
# 优先处理 /jiaocheng 路径(放在最前面)
location /jiaocheng {
# 匹配 /jiaocheng 或 /jiaocheng/,指向 help 插件的入口文件
rewrite ^/jiaocheng/?$ /content/plugins/help/index.php last;
# 文章页:/jiaocheng/123.html 指向 /jiaocheng/123 指向 help 插件
rewrite ^/jiaocheng/(\d+)\.html$ /content/plugins/help/index.php?post=$1 last;
rewrite ^/jiaocheng/(\d+)/?$ /content/plugins/help/index.php?post=$1 last;
# 分类页:/jiaocheng/sort/5 指向 help 插件
rewrite ^/jiaocheng/sort/(\d+)$ /content/plugins/help/index.php?sort=$1 last;
}
# 原有 help 路径的兼容处理(可选,保留可访问 /help)
location /help {
rewrite ^/help/?$ /content/plugins/help/index.php last;
rewrite ^/help/(\d+)\.html$ /content/plugins/help/index.php?post=$1 last;
rewrite ^/help/(\d+)/?$ /content/plugins/help/index.php?post=$1 last;
rewrite ^/help/sort/(\d+)$ /content/plugins/help/index.php?sort=$1 last;
}
# 网站主规则(放在最后)
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php last;
}
}
在网站根目录的 .htaccess 文件中添加以下规则(如果没有则创建):
# 允许访问jiaocheng目录
RewriteEngine On
# 教程中心首页:访问/jiaocheng时指向/jiaocheng/index.php
RewriteRule ^jiaocheng/?$ /jiaocheng/index.php [L]
# 教程中心文章页:/jiaocheng/123.html 指向/jiaocheng/index.php?post=123
RewriteRule ^jiaocheng/(\d+)\.html$ /jiaocheng/index.php?post=$1 [L]
# 教程中心分类页:/jiaocheng/sort/5 指向/jiaocheng/index.php?sort=5
RewriteRule ^jiaocheng/sort/(\d+)$ /jiaocheng/index.php?sort=$1 [L]
在 Nginx 站点配置文件中添加以下规则:
location /jiaocheng {
# 首页指向index.php
if ($request_uri ~ ^/jiaocheng/?$) {
rewrite ^ /jiaocheng/index.php last;
}
# 文章页:/jiaocheng/123.html 指向index.php?post=123
if ($request_uri ~ ^/jiaocheng/(\d+)\.html$) {
rewrite ^ /jiaocheng/index.php?post=$1 last;
}
# 分类页:/jiaocheng/sort/5 指向index.php?sort=5
if ($request_uri ~ ^/jiaocheng/sort/(\d+)$) {
rewrite ^ /jiaocheng/index.php?sort=$1 last;
}
}
<?php
if (!defined('EMLOG_ROOT')) {
require_once '../../init.php';
}
// 检查插件是否启用
$jiaocheng_storage = Storage::getInstance('plugin_jiaocheng');
$is_open = $jiaocheng_storage->getValue('is_open', 'on');
if ($is_open !== 'on') {
exit('教程插件已关闭');
}
// 验证密码(如果设置了)
$password = $jiaocheng_storage->getValue('password', '');
if (!empty($password) && (!isset($_POST['jiaocheng_pwd']) || $_POST['jiaocheng_pwd'] !== $password)) {
echo '<form method="post" style="text-align:center;margin-top:50px;">';
echo '<h3>请输入访问密码</h3>';
echo '<input type="password" name="jiaocheng_pwd" placeholder="密码">';
echo '<button type="submit">提交</button>';
echo '</form>';
exit;
}
// 引入显示逻辑
include_once 'jiaocheng_show.php';
<?php
if (!defined('EMLOG_ROOT')) {
require_once '../../init.php';
}
// 检查插件是否启用
$jiaocheng_storage = Storage::getInstance('plugin_jiaocheng');
$is_open = $jiaocheng_storage->getValue('is_open', 'on');
if ($is_open !== 'on') {
exit('教程插件已关闭');
}
// 验证密码
$password = $jiaocheng_storage->getValue('password', '');
if (!empty($password)) {
session_start();
// 密码验证通过则记录会话
if (isset($_POST['jiaocheng_pwd']) && $_POST['jiaocheng_pwd'] === $password) {
$_SESSION['jiaocheng_auth'] = true;
}
// 未通过验证则显示密码框
if (!isset($_SESSION['jiaocheng_auth']) || $_SESSION['jiaocheng_auth'] !== true) {
echo '<form method="post" style="text-align:center;margin-top:50px;">';
echo '<h3>请输入访问密码</h3>';
echo '<input type="password" name="jiaocheng_pwd" placeholder="密码">';
echo '<button type="submit">提交</button>';
echo '</form>';
exit;
}
}
// 引入显示逻辑
include_once 'jiaocheng_show.php';
版权所有:
鲜易达电子商务有限公司
文章标题:
教程中心伪静态规则
文章链接:https://xianyida.ysxdo.com/post-55.html
本站文章均为原创,未经授权请勿用于任何商业用途
撰写评论