# 伪静态(url重写)
## apache 伪静态
在public下新建.htaccess文件,复制以下代码。注意:public目录下是自带该文件的。
```
<pre class="calibre16">```
<span class="token"><</span>IfModule mod_rewrite<span class="token1">.</span>c<span class="token">></span>
Options <span class="token">+</span>FollowSymlinks <span class="token">-</span>Multiviews
RewriteEngine On
RewriteCond <span class="token">%</span><span class="token1">{</span>REQUEST_FILENAME<span class="token1">}</span> <span class="token">!</span><span class="token">-</span>d
RewriteCond <span class="token">%</span><span class="token1">{</span>REQUEST_FILENAME<span class="token1">}</span> <span class="token">!</span><span class="token">-</span>f
RewriteRule <span class="token">^</span><span class="token1">(</span><span class="token1">.</span><span class="token">*</span><span class="token1">)</span>$ index<span class="token1">.</span>php <span class="token1">[</span>L<span class="token1">,</span>E<span class="token">=</span>PATH_INFO<span class="token1">:</span>$<span class="token3">1</span><span class="token1">]</span>
<span class="token"><</span><span class="token">/</span>IfModule<span class="token">></span>
```
```
## nginx 伪静态 参考
1. 宝塔服务器参考[Linux下宝塔安装](LinuxXia%20Bao%20Ta%20An%20Zhuang.html)
找到nginx网站配置文件,打开后在合适位置增加以下配置
```
<pre class="calibre16">```
#伪静态配置,重写规则引用<span class="token1">,</span>修改后将导致伪静态规则失效
location <span class="token">/</span> <span class="token1">{</span>
<span class="token2">if</span> <span class="token1">(</span><span class="token">!</span><span class="token">-</span>e $request_filename<span class="token1">)</span><span class="token1">{</span>
rewrite <span class="token">^</span><span class="token1">(</span><span class="token1">.</span><span class="token">*</span><span class="token1">)</span>$ <span class="token">/</span>index<span class="token1">.</span>php<span class="token">?</span>s<span class="token">=</span>$<span class="token3">1</span> last<span class="token1">;</span> <span class="token2">break</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span>
```
```
完整nginx配置参考
```
<pre class="calibre16">```
server
<span class="token1">{</span>
listen <span class="token3">80</span><span class="token1">;</span>
server_name <span class="token3">192.168</span><span class="token3">.0</span><span class="token3">.118</span><span class="token1">;</span>
index index<span class="token1">.</span>php index<span class="token1">.</span>html<span class="token1">;</span>
root <span class="token">/</span>www<span class="token">/</span>data<span class="token">/</span>HkCms<span class="token">/</span>public<span class="token1">;</span>
#PHP引用配置
location <span class="token">~</span> <span class="token1">[</span><span class="token">^</span><span class="token">/</span><span class="token1">]</span>\<span class="token1">.</span><span class="token6">php</span><span class="token1">(</span><span class="token">/</span><span class="token">|</span>$<span class="token1">)</span>
<span class="token1">{</span>
try_files $uri <span class="token">=</span><span class="token3">404</span><span class="token1">;</span>
# Socket管道方式
# fastcgi_pass unix<span class="token1">:</span><span class="token">/</span>tmp<span class="token">/</span>php<span class="token">-</span>cgi<span class="token">-</span><span class="token3">71.</span>sock<span class="token1">;</span>
# tcpip方式<span class="token1">,</span> 端口根据PHP<span class="token">-</span>FPM配置文件
fastcgi_pass <span class="token3">127.0</span><span class="token3">.0</span><span class="token3">.1</span><span class="token1">:</span><span class="token3">10711</span><span class="token1">;</span>
fastcgi_split_path_info <span class="token">^</span><span class="token1">(</span><span class="token1">(</span><span class="token">?</span>U<span class="token1">)</span><span class="token1">.</span><span class="token">+</span>\<span class="token1">.</span>php<span class="token1">)</span><span class="token1">(</span><span class="token">/</span><span class="token">?</span><span class="token1">.</span><span class="token">+</span><span class="token1">)</span>$<span class="token1">;</span>
fastcgi_index index<span class="token1">.</span>php<span class="token1">;</span>
# 引用fastcgi_param参数
include fastcgi<span class="token1">.</span>conf<span class="token1">;</span>
set $real_script_name $fastcgi_script_name<span class="token1">;</span>
<span class="token2">if</span> <span class="token1">(</span>$fastcgi_script_name <span class="token">~</span> <span class="token4">"^(.+?\.php)(/.+)$"</span><span class="token1">)</span> <span class="token1">{</span>
set $real_script_name $<span class="token3">1</span><span class="token1">;</span>
set $path_info $<span class="token3">2</span><span class="token1">;</span>
<span class="token1">}</span>
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name<span class="token1">;</span>
fastcgi_param SCRIPT_NAME $real_script_name<span class="token1">;</span>
fastcgi_param PATH_INFO $path_info<span class="token1">;</span>
<span class="token1">}</span>
#伪静态配置,重写规则引用<span class="token1">,</span>修改后将导致伪静态规则失效
location <span class="token">/</span> <span class="token1">{</span>
<span class="token2">if</span> <span class="token1">(</span><span class="token">!</span><span class="token">-</span>e $request_filename<span class="token1">)</span><span class="token1">{</span>
rewrite <span class="token">^</span><span class="token1">(</span><span class="token1">.</span><span class="token">*</span><span class="token1">)</span>$ <span class="token">/</span>index<span class="token1">.</span>php<span class="token">?</span>s<span class="token">=</span>$<span class="token3">1</span> last<span class="token1">;</span> <span class="token2">break</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span>
#禁止用户上传目录下所有<span class="token1">.</span>php文件的访问,提高安全性
location <span class="token">~</span> <span class="token">^</span><span class="token">/</span>uploads<span class="token">/</span><span class="token1">.</span><span class="token">*</span>\<span class="token1">.</span><span class="token1">(</span>php<span class="token">|</span>php5<span class="token1">)</span>$ <span class="token1">{</span>
deny all<span class="token1">;</span>
<span class="token1">}</span>
#禁止访问的文件或目录
location <span class="token">~</span> <span class="token">^</span><span class="token">/</span><span class="token1">(</span>\<span class="token1">.</span>user<span class="token1">.</span>ini<span class="token">|</span>\<span class="token1">.</span>htaccess<span class="token">|</span>\<span class="token1">.</span>git<span class="token">|</span>\<span class="token1">.</span>svn<span class="token">|</span>\<span class="token1">.</span>project<span class="token">|</span>LICENSE<span class="token">|</span>README<span class="token1">.</span>md<span class="token1">)</span>
<span class="token1">{</span>
<span class="token2">return</span> <span class="token3">404</span><span class="token1">;</span>
<span class="token1">}</span>
location <span class="token">~</span> <span class="token1">.</span><span class="token">*</span>\<span class="token1">.</span><span class="token1">(</span>gif<span class="token">|</span>jpg<span class="token">|</span>jpeg<span class="token">|</span>png<span class="token">|</span>bmp<span class="token">|</span>swf<span class="token1">)</span>$
<span class="token1">{</span>
expires <span class="token3">30</span>d<span class="token1">;</span>
error_log <span class="token">/</span>dev<span class="token">/</span><span class="token2">null</span><span class="token1">;</span>
access_log off<span class="token1">;</span>
<span class="token1">}</span>
location <span class="token">~</span> <span class="token1">.</span><span class="token">*</span>\<span class="token1">.</span><span class="token1">(</span>js<span class="token">|</span>css<span class="token1">)</span><span class="token">?</span>$
<span class="token1">{</span>
expires <span class="token3">12</span>h<span class="token1">;</span>
error_log <span class="token">/</span>dev<span class="token">/</span><span class="token2">null</span><span class="token1">;</span>
access_log off<span class="token1">;</span>
<span class="token1">}</span>
# 访问日志
access_log <span class="token">/</span>www<span class="token">/</span>wwwlogs<span class="token">/</span><span class="token3">192.168</span><span class="token3">.0</span><span class="token3">.118</span><span class="token1">.</span>log<span class="token1">;</span>
# 错误日志
error_log <span class="token">/</span>www<span class="token">/</span>wwwlogs<span class="token">/</span><span class="token3">192.168</span><span class="token3">.0</span><span class="token3">.118</span><span class="token1">.</span>error<span class="token1">.</span>log<span class="token1">;</span>
<span class="token1">}</span>
```
```
## IIS参考
主要添加的内容
```
<pre class="calibre16">```
<span class="token"><</span>rewrite<span class="token">></span>
<span class="token"><</span>rules<span class="token">></span>
<span class="token"><</span>rule name<span class="token">=</span><span class="token4">"OrgPage"</span> stopProcessing<span class="token">=</span><span class="token4">"true"</span><span class="token">></span>
<span class="token"><</span>match url<span class="token">=</span><span class="token4">"^(.*)$"</span> <span class="token">/</span><span class="token">></span>
<span class="token"><</span>conditions logicalGrouping<span class="token">=</span><span class="token4">"MatchAll"</span><span class="token">></span>
<span class="token"><</span>add input<span class="token">=</span><span class="token4">"{HTTP_HOST}"</span> pattern<span class="token">=</span><span class="token4">"^(.*)$"</span> <span class="token">/</span><span class="token">></span>
<span class="token"><</span>add input<span class="token">=</span><span class="token4">"{REQUEST_FILENAME}"</span> matchType<span class="token">=</span><span class="token4">"IsFile"</span> negate<span class="token">=</span><span class="token4">"true"</span> <span class="token">/</span><span class="token">></span>
<span class="token"><</span>add input<span class="token">=</span><span class="token4">"{REQUEST_FILENAME}"</span> matchType<span class="token">=</span><span class="token4">"IsDirectory"</span> negate<span class="token">=</span><span class="token4">"true"</span> <span class="token">/</span><span class="token">></span>
<span class="token"><</span><span class="token">/</span>conditions<span class="token">></span>
<span class="token"><</span>action type<span class="token">=</span><span class="token4">"Rewrite"</span> url<span class="token">=</span><span class="token4">"index.php/{R:1}"</span> <span class="token">/</span><span class="token">></span>
<span class="token"><</span><span class="token">/</span>rule<span class="token">></span>
<span class="token"><</span><span class="token">/</span>rules<span class="token">></span>
<span class="token"><</span><span class="token">/</span>rewrite<span class="token">></span>
```
```
添加的位置
```
<pre class="calibre20">```
<span class="token"><</span><span class="token">?</span>xml version<span class="token">=</span><span class="token4">"1.0"</span> encoding<span class="token">=</span><span class="token4">"UTF-8"</span><span class="token">?</span><span class="token">></span>
<span class="token"><</span>configuration<span class="token">></span>
<span class="token"><</span>system<span class="token1">.</span>webServer<span class="token">></span>
<span class="token"><</span>rewrite<span class="token">></span>
<span class="token"><</span>rules<span class="token">></span>
<span class="token"><</span>rule name<span class="token">=</span><span class="token4">"OrgPage"</span> stopProcessing<span class="token">=</span><span class="token4">"true"</span><span class="token">></span>
<span class="token"><</span>match url<span class="token">=</span><span class="token4">"^(.*)$"</span> <span class="token">/</span><span class="token">></span>
<span class="token"><</span>conditions logicalGrouping<span class="token">=</span><span class="token4">"MatchAll"</span><span class="token">></span>
<span class="token"><</span>add input<span class="token">=</span><span class="token4">"{HTTP_HOST}"</span> pattern<span class="token">=</span><span class="token4">"^(.*)$"</span> <span class="token">/</span><span class="token">></span>
<span class="token"><</span>add input<span class="token">=</span><span class="token4">"{REQUEST_FILENAME}"</span> matchType<span class="token">=</span><span class="token4">"IsFile"</span> negate<span class="token">=</span><span class="token4">"true"</span> <span class="token">/</span><span class="token">></span>
<span class="token"><</span>add input<span class="token">=</span><span class="token4">"{REQUEST_FILENAME}"</span> matchType<span class="token">=</span><span class="token4">"IsDirectory"</span> negate<span class="token">=</span><span class="token4">"true"</span> <span class="token">/</span><span class="token">></span>
<span class="token"><</span><span class="token">/</span>conditions<span class="token">></span>
<span class="token"><</span>action type<span class="token">=</span><span class="token4">"Rewrite"</span> url<span class="token">=</span><span class="token4">"index.php/{R:1}"</span> <span class="token">/</span><span class="token">></span>
<span class="token"><</span><span class="token">/</span>rule<span class="token">></span>
<span class="token"><</span><span class="token">/</span>rules<span class="token">></span>
<span class="token"><</span><span class="token">/</span>rewrite<span class="token">></span>
<span class="token"><</span>handlers<span class="token">></span>
<span class="token"><</span><span class="token">/</span>handlers<span class="token">></span>
<span class="token"><</span><span class="token">/</span>system<span class="token1">.</span>webServer<span class="token">></span>
<span class="token"><</span><span class="token">/</span>configuration<span class="token">></span>
```
```
- 简介
- 下载与安装配置
- 下载
- 虚拟主机安装
- 百度云虚拟主机
- 创业云虚拟主机
- Linux下宝塔安装
- 宝塔一键部署
- Windows下宝塔安装
- phpEnv下安装
- phpStudy下安装
- 伪静态(url重写)
- 安装系统
- 调试模式与env文件
- 重新安装与安装文件说明
- 后台使用帮助
- 后台入口文件
- 首页面板
- 配置中心
- 站点配置
- SEO设置
- SEO设置-静态生成
- 文档属性
- 站点模块
- V2.2.2版本 -
- V2.2.3版本 +
- 模型管理
- 栏目管理
- 字段类型与组件
- 前言
- 前端组件
- 验证规则
- text 单行文本
- textarea 多行文本
- radio 单选
- checkbox 复选
- select 下拉列表
- selects下拉列表(多)
- selectpage 动态下拉
- editor编辑器
- image图片
- images图片(多)
- number数字
- date日期
- datetime日期和时间
- downfile文件上传
- downfiles文件上传(多)
- array 数组(键值对)
- 内容管理
- 自定义URL
- 多语言
- 界面多语言
- 内容多语言
- 多语言URL地址
- 附件管理
- 应用中心
- 标签语法
- 标签使用必读
- 列表标签
- content 内容列表标签
- contentpage 内容列表分页
- wfpage 瀑布流分页
- filter 筛选标签
- order 排序标签
- 内容标签
- guestbook 留言(表单)标签(废弃)
- form 表单标签
- pre 上一篇标签
- next 下一篇标签
- prenext 上一篇下一篇(高级)标签
- fileinfo 获取附件信息(文件下载)
- 内容分页
- raw 格式化编辑器文本(即将废弃)
- 全局标签
- seo 标签
- channel 栏目标签
- arcone 获取单条文档
- breadcrumb 面包屑导航标签
- adv 站点模块标签
- date 日期格式化标签
- substr字符(标题)截取标签
- volist 循环标签
- language 获取语言列表标签
- query 查询数据库内容
- include 导入模板文件标签
- 原生PHP与php标签
- map生成位置地图
- thumb 生成缩略图
- addons 插件检测
- 标签管理
- taglist标签(获取标签列表)
- tagarclist根据标签获取文章内容列表
- 导入标签
- 模板开发
- 1. 创建模板
- 2. 模板目录结构
- 3. 模板描述文件(重要) info.ini
- 4. 变量输出格式
- 4. 模板变量
- 5. 获取站点配置
- 6. 模板界面多语言
- 7. 模板静态目录及调用静态文件
- 8. 模板定义插件事件
- 9. 模板搜索页
- 10. 模板配置JSON
- 11. 导入演示数据
- 12. 卸载删除演示数据
- 13. 模板文件打包
- 14. 整站源码打包
- 插件开发
- 1. 创建插件
- 2. 目录结构
- 3. 插件名称类
- 4. 插件信息(info.ini)
- 5. 插件事件
- 6. 配置文件
- 7. install 安装目录
- 8. 创建菜单
- 9. 插件控制器
- 10. 插件视图
- 10-1 插件主题化
- 11. 插件模型
- 12. 模型事件
- 13. 插件内置函数
- 13-1 插件函数库
- 14. 插件多语言
- 15. 插件中间件
- 16. 插件路由
- 17. 插件验证器
- 18. 标签库
- 19. 第三方类库
- 20. 数据库文件导入
- 插件打包
- 后台前端使用帮助
- 二次开发帮助(更新中)
- 后台前端开发帮助
- 路由(链接地址、访问规则)
- URL访问
- 路由定义
- URL生成
- 附录
- 数据字典
- 助手函数库