一.入口模块修改

修改public下的index 加入 define('BIND_MODULE','admin'); 即可将入门模块绑定到admin模块

<?php

// [ 应用入口文件 ]

// 定义应用目录
define('APP_PATH', __DIR__ . '/../application/'); //定义配置文件目录
define('CONF_PATH',__DIR__.'/../conf/');
define('BIND_MODULE','admin');
// 加载框架引导文件
require __DIR__ . '/../thinkphp/start.php';

二.路由美化  在conf 目录创建route.php

1.开启路由配置

// 是否开启路由
'url_route_on' => true,
// 是否强制使用路由
'url_route_must' => false,

2.在conf目录新建 route.php

<?php

return [
'new/:id' => 'admin/index/index',
];

3.助手函数 url()直接修改url

  public function index($id){
echo url('admin/index/index',['id'=>11]).'<br />';
return "index";
}

4.route.php 路由规则

'news/' => 'admin/index/index',  // 添加路由规则 路由到 index控制器的index操作方法
http://localhost/index
'news/:id' => 'admin/index/index', //该路由规则表示所有index开头的并且带参数的访问都会路由到index控制器的index操作方法,且参数不能为空
http://localhost/index?id=6&name=dd
'news/[:id]' => 'admin/index/index',  // 路由参数name为可选
http://localhost/index?id=7 或 http://localhost/index 均可
 

动态路由

/* 动态路由设置 */
use \think\Route;
/* 将Index控制器设置别名为斜杠 / */
Route::alias('test','\app\index\controller\Test'); /* 设置路由规则 */
Route::rule([
'news/:id' => 'index/test/index',
'blog/:id' => ['Blog/update',['ext'=>'html'],['id'=>'\d{4}']],],'','GET',['ext'=>'html'],['id'=>'\d+']);

静态路由 在conf目录route文件配置

<?php
return
# ext 为url后缀
['news/:name' => 'index/test/test',['ext'=>'html']]
;

apache2 配置文件在public .htaccess

 /* vim /etc/apache2/apache2.conf  */

<IfModule mod_rewrite.c>
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.html)$ [NC]
RewriteRule ^/?(.*)$ /$1.html [QSA,R=301,L] RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] #//第二种方法
#RewriteEngine on
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

浏览器访问时 在phpstorm调试时要加index.php 例如下面的url要写成  https/localhost/index.php/news/6.html 不然无法访问。

生产环境不用加index.php

以下可以不用设置

1.修改apache2服务器的httpd.conf

var/www# vim /usr/local/apache2/conf/httpd.conf

确认加载了 mod_rewrite.so 模块(将如下配置前的 # 号去掉):

LoadModule rewrite_module modules/mod_rewrite.so

更改AllowOverride 配置

<Directory /var/www/tp5/public>
MultiViews
Options Indexes FollowSymLinks
AllowOverride FileInfo Options
#AllowOverride None Require all granted
</Directory>

最新文章

  1. 利用scp 远程上传下载文件/文件夹和ssh远程执行命令
  2. 网页端压缩解压缩插件JSZIP库的使用
  3. UDP发送数据测试
  4. json转换为javabean
  5. 搭建angularjs API文档站点
  6. 如何查询Oracle中用户所有信息
  7. 关于JavaScript的思考
  8. CSS文字大小单位px、em、pt(转)
  9. Access增删改查 (持续更新中)
  10. BZOJ3166: [Heoi2013]Alo
  11. app被Rejected 的各种原因翻译(转)
  12. ios创建画笔的样例(双笔画效果)
  13. unity3d 学习笔记(两)
  14. Java基础---Java---网络编程---TCP的传输、客户端和服务端的互访、建立一个文本转换器、编写一个聊天程序
  15. Nginx Install 记录
  16. 从Java小白到收获BAT等offer,分享我这两年的经验和感悟
  17. lnmp 搭建 初试
  18. 洛谷P2239 螺旋矩阵
  19. 一个源文件可以写出多个class吗?编译后,会不会生成多个class文件?
  20. Tom与Jerry谁先死?

热门文章

  1. linux让命令或程序在终端后台运行的方法(Ubuntu/Fedora/Centos等一样适用)
  2. windows下数据库备份bat
  3. pl/sql的安装使用详解
  4. Gym 100507H - Pair: normal and paranormal
  5. 阶段1 语言基础+高级_1-3-Java语言高级_05-异常与多线程_第3节 线程同步机制_1_线程安全问题的概述
  6. 基于3ds Max的游戏建模方案
  7. 【Unity Shader】---CG标准函数库
  8. vue登录注册实践
  9. 在VS Code中使用Jupyter Notebook
  10. 加密算法:DES、AES等