#### 实现伪静态
Apache的Mod_Rewrite对URL进行重写,实现网站伪静态化。
配置步骤:
第一步:打开apache的配置文件httpd.conf ,找到
` #LoadModule rewrite_module modules/mod_rewrite.so`
把前面#去掉。没有则添加,但必选独占一行,使apache支持 mod_rewrite 模块
第二步:找到
~~~
<Directory "D:/ApacheServer/web">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
~~~
把 AllowOverride None 换成 AllowOverride All 使apache支持 .htaccess 文件
第三步:重启apache服务器
在要启用伪静态的 PHP 项目根目录下建立 .htaccess 文件, 在 .htaccess 文件中输入内容
~~~
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule index.html$ index.php
RewriteRule index-([1-9]+[0-9]*).html$ index.php?p=$1
RewriteRule ([a-z]{1,})-([0-9]{1,}).html$ index.php?action=$1&id=$2
</IfModule>
~~~
注释:
RewriteEngine 为重写引擎开关,on为开启,off为关闭。
RewriteRule 是路由转向规则,之前路径为浏览器中要输入路径,这里可以用正则表达式表达。+空格 后路径为后台实际转向路径,
转向后台实际路径时可以传参数,例子里的后台页面可以用GET[′p′]_GET[‘action’] GET[‘id′]来接收1 代表浏览器路径中输入的第一个正则表达式的值,以此类推,$2代表第二个正则表达式的值
RewriteRule 路由转向规则里正则表达式用括号 () 括起来
例子所在项目为test
在项目下 index.php 页面内写入内容
~~~
<?php
if ($_GET ['p']) {
echo "p : " . $_GET ['p'];
}
if ($_GET ['action']) {
echo "action : " . $_GET ['action'];
}
if ($_GET ['id']) {
echo "id : " . $_GET ['id'];
}
?>
~~~
在浏览器中输入
http://localhost/test/index.html
http://localhost/test/index-99.html
http://localhost/test/page-18.html
都会转向 http://localhost/test/index.php 页面
并且依次
http://localhost/test/index.html 页面什么都不显示
http://localhost/test/index-99.html 页面显示 p : 99
http://localhost/test/page-18.html 页面显示 action : pageid : 18
配置完成。
#### ab压测
~~~
// 在Windows系统下,打开cmd命令行窗口,定位到apache安装目录的bin目录下
cd C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin
// 键入命令:
ab -n 800 -c 800 http://192.168.0.10/
// -n发出800个请求,-c模拟800并发,相当800人同时访问,后面是测试url
ab -t 60 -c 100 http://192.168.0.10/
// 在60秒内发请求,一次100个请求
~~~
- JavaScript笔记
- JQuery
- Echarts初级入门
- Js常用正则表达式
- 使用vuejs前端框架
- Bootbox.js官方文档中文版
- LocalStorage基本用法小结
- Toastr消息提示插件中文文档
- Ajax提交Form数据及文件上传
- Nodejs笔记
- Python笔记
- Scrapy爬虫技术
- Django框架
- Java笔记
- 环境搭建
- Php笔记
- MacOS 10.13.6搭建PHP开发环境
- Php常见问题及解决方法
- 玩转laravel之homestead
- Apache服务器的基本操作
- 如何使用CentOS7 + Lnmp
- ThinkPHP爬坑之路
- 初识Swoole
- 小贴士
- 习题集
- 方法集
- 数据库
- mysql
- 常用的SQL语句
- 日常操作和设置
- 常见问题及解决办法
- 读写分离和主从复制
- 数据表分区
- postgresql
- 在PHP中的应用
- redis
- 测试
- 接口测试
- Web测试
- 杂项
- Sublime text3使用小贴士
- 利用虚拟机学习Linux
- PHPstorm常用设置
- Windows实用tips
- 微信开发小知识
- Git常用操作
- Swift入门
- 机器学习
- 系统命令
- 网络拾贝
