轻灵CMS 伪静态配置教程
轻灵CMS 支持伪静态(URL重写),开启后文章的访问地址从 /index.php?c=article&a=detail&slug=xxx 变成 /xxx.html,更美观也更利于SEO。
一、Linux 虚拟主机(Apache)
虚拟主机通常会自动读取网站根目录的 .htaccess 文件。程序已自带该文件,无需任何额外操作。
如果不慎丢失,将下方代码保存为 .htaccess 并上传到网站根目录即可:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# 禁止直接访问敏感目录
RewriteRule ^(data|core|app)/ - [F,L]
# 如果请求的是真实文件或目录,直接访问
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# 重写所有请求到index.php
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
# 禁止访问敏感文件
<FilesMatch "\.(db|sqlite|sql|log|lock)$">
Order Allow,Deny
Deny from all
</FilesMatch>
# 禁止访问配置文件
<FilesMatch "^config\.php$">
Order Allow,Deny
Deny from all
</FilesMatch>
# 禁止目录浏览
Options -Indexes
# 设置默认首页
DirectoryIndex index.php二、Linux 服务器 + 宝塔面板
1. NGINX
宝塔面板 → 网站 → 设置 → 伪静态,将下方代码粘贴进去,保存即可:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* \.(db|sqlite|sql|log|lock)$ {
deny all;
}
location ~* /config\.php$ {
deny all;
}
location ~* \.(jpg|jpeg|png|gif|webp|ico|css|js|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}2. Apache
宝塔面板 → 网站 → 设置 → 伪静态,将下方代码粘贴进去,保存即可:
RewriteEngine On
RewriteBase /
# 禁止直接访问敏感目录
RewriteRule ^(data|core|app)/ - [F,L]
# 如果请求的是真实文件或目录,直接访问
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# 重写所有请求到index.php
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
# 禁止访问敏感文件
<FilesMatch "\.(db|sqlite|sql|log|lock)$">
Order Allow,Deny
Deny from all
</FilesMatch>
# 禁止访问配置文件
<FilesMatch "^config\.php$">
Order Allow,Deny
Deny from all
</FilesMatch>
# 禁止目录浏览
Options -Indexes说明
- 安全保护:已自动禁止直接访问
.db、.sqlite等数据库文件以及config.php配置文件。 - 静态资源缓存:NGINX 配置中已包含图片、CSS、JS 等静态资源的浏览器缓存(30天),提升加载速度。
- 确认开启:确保
config.php中URL_REWRITE设置为true(默认已开启)。
评论
暂无评论,快来抢沙发吧!
发表评论