伪静态规则配置教程
伪静态是将动态URL转换为静态URL格式,有利于SEO优化。
伪静态的作用:
- 提高搜索引擎收录
- 增强URL可读性
- 隐藏真实程序路径
Linux主机(Apache .htaccess):
开启伪静态:
RewriteEngine On
常用规则示例:
将所有请求指向index.php:
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule ^(.*)$ index.php/$1 [L]
隐藏.php后缀:
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteRule ^([^\.]+)$ $1.php [NC,L]
WordPress伪静态:
- RewriteEngine On
- RewriteBase /
- RewriteRule ^index\.php$ - [L]
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule . /index.php [L]
Windows主机(IIS web.config):
需要在web.config中配置URL重写规则。
注意事项:
- 上传.htaccess文件到网站根目录
- 确保主机支持伪静态
- 规则错误可能导致网站500错误
- 修改后建议备份原文件