apache 使用htaccess自定义路由机制
2016-06-06 21:34
465 查看
先开启伪静态。详情查看这篇文章:http://www.cnblogs.com/CyLee/p/5544119.html
然后在项目根目录中新建一个.htaccess文件,加入以下代码
正则中()的变量 == $1,$2,$3,$4...
&%1是忽略、去掉不关注的字符串
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteRule ^css/(.*) /MVC/V/A001/css/$1
RewriteRule ^js/(.*) /MVC/V/A001/js/$1
RewriteCond %{QUERY_STRING} ^(.*)
RewriteRule ^([a-zA-Z_]{2,10})/?$ /index.php?controller=$1&%1
RewriteCond %{QUERY_STRING} ^(.*)
RewriteRule ^([a-zA-Z_]{2,10})/([a-zA-Z_]{1,20})/?$ /index.php?controller=$1&action=$2&%1
</ifmodule>
当访问shenyi.com/index/index/时,等同于访问localhost:80/index.php?controller=index&action=index
然后在项目根目录中新建一个.htaccess文件,加入以下代码
正则中()的变量 == $1,$2,$3,$4...
&%1是忽略、去掉不关注的字符串
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteRule ^css/(.*) /MVC/V/A001/css/$1
RewriteRule ^js/(.*) /MVC/V/A001/js/$1
RewriteCond %{QUERY_STRING} ^(.*)
RewriteRule ^([a-zA-Z_]{2,10})/?$ /index.php?controller=$1&%1
RewriteCond %{QUERY_STRING} ^(.*)
RewriteRule ^([a-zA-Z_]{2,10})/([a-zA-Z_]{1,20})/?$ /index.php?controller=$1&action=$2&%1
</ifmodule>
当访问shenyi.com/index/index/时,等同于访问localhost:80/index.php?controller=index&action=index
相关文章推荐
- 安装apache solr
- PHP脚本Apache用户下执行Java命令报exec: java: not found
- Apache服务器常规操作
- apache无法启动提示the requested operation has failed的解决方法
- apache日志按日期进行分割
- Apache shiro集群实现 (一) shiro入门介绍
- apache.commons.lang.StringUtils 字符串Utils
- PHP7.0与Apache相应配置
- Apache james 2.3.2.1启动失败换成2.3.2版本就好
- apache hadoop namenode的HA搭建
- Apache AB 参数传递
- Apache 服务器 自带的压力测试工具ab 的使用
- Apache日志配置远程Syslog采集
- LAMP环境官方最新源码编译安装
- Apache随机出现403 Forbidden探析
- Apache 2.2 安装好后新建任意 PHP 文件访问时返回 500 Internal Server Error 解决方法
- MySQL, Apache, PHP 安装教程
- apache mina: 写数据过程
- apache mina : 用户自定义数据存储
- 使用apache common-io 监控文件变化