Apache RewriteCond RewriteRule 入门和Laravel去掉index.php
Ci删除index.php办法:
创建.htaccess 文件放到网站的根目录下,文件中的内容如下:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f //此处有大坑。加上这句可保证一般css、js文件正常加载。(注意删掉这句注释哦)
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
注意:如果你的项目不在根目录请把上面这一句改为:RewriteRule ^(.*)$ index.php/$1 [L]
在上面的例子中,可以实现任何非 index.php、images 和 robots.txt 的 HTTP 请求都被指向 index.php。
一篇文章:
Apache中 RewriteCond语句对于我来说一直是个难点,多次试图去把它搞明白,都没有结构,这次我终于算大概知道它的意思了。
RewriteCond就像我们程序中的if语句一样,表示如果符合某个或某几个条件则执行RewriteCond下面紧邻的RewriteRule语句,这就是RewriteCond最原始、基础的功能,为了方便理解,下面来看看几个例子。
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/5.0.*
RewriteRule index.php index.m.php RewriteCond %{HTTP_USER_AGENT} ^Lynx.*
RewriteRule index.php index.L.php RewriteRule index.php index.b.php
上 面语句的作用是当你是用FF浏览器访问index.php这个文件的时候,会自动让你访问到index.m.php这个文件,当你是用一些移动终端访问的 时候,会让你对index.php这个文件的访问实际访问的是index.L.php去,如果你是用其它的浏览器访问的时候,会让你跳到 index.b.php。在说形象一点,上面的语句就等同于程序里面的下面语句(依PHP语句为例):
if($_SERVER['HTTP_USER_AGENT'] == 'Mozilla/5.0'){//跳转到对index.m.php的访问}else if($_SERVER['HTTP_USER_AGENT'] == 'Lynx'){//跳转到对index.L.php的访问}else//跳转到对index.b.php的访问RewriteCond %{HTTP_REFERER} (www.test.cn)RewriteRule (.*)$ test.phpRewriteCond %{REMOTE_HOST} ^host1.* [OR]RewriteCond %{REMOTE_HOST} ^host2.* [OR]RewriteCond %{REMOTE_HOST} ^host3.*RewriteRule (.*)$ test.phpRewriteCond %{REQUEST_FILENAME} !-f //如果文件存在,就直接访问文件,不进行下面的RewriteRule.(不是文件或文件不存在就执行重写)RewriteCond %{REQUEST_FILENAME} !-d //#如果目录存在就直接访问目录不进行RewriteRuleRewriteCond %{REQUEST_URI} !^.*(.css|.js|.gif|.png|.jpg|.jpeg)$ //#如果是这些后缀的文件,就直接访问文件,不进行Rewritehttp://www.zzbaike.com/wiki/Htaccess
转自:http://www.skygq.com/2011/02/21/apache%E4%B8%ADrewritecond%E8%A7%84%E5%88%99%E5%8F%82%E6%95%B0%E4%BB%8B%E7%BB%8D%E8%BD%AC/
laravel去掉index.php
配置.htaccess文件 ---find / -name .htaccess 来查找此文件
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] ---这句话的含义是:任何访问网站的路径都映射成index.php/xxx,其中xxx是$1 与 (.*)中的内容进行匹配 例如我们输入http://192.168.0.222/about -->http://192.168.0.222/index.php/about
</IfModule>
3,如果是专门针对laravel进行配置,则在app/app.php中加入
index=>'', //laravel4.1中没有此项,直接手写加入即可 (好像不起作用)
Apache RewriteCond RewriteRule 入门和Laravel去掉index.php的更多相关文章
- apache RewriteCond RewriteRule
http://www.rockbb.com/blog/?p=319 http://www.cnblogs.com/scgw/archive/2011/12/10/2283029.html 我的理解:当 ...
- laravel 去掉index.php伪静态
1,首先,让apache服务器支持rewrite 可以在apache配置文件中定义rewrite规则,是全局的,无论哪个应用都实用 //httpd.config Listen 80 RewriteEn ...
- CodeIgniter 框架在Apache服务器下去掉index.php 总结
最近一段时间一直研究CI框架,但是对CI框架的跳转链接一直需要加index.php前缀,经过CI论坛的各种解决方案,最后总结记录一下自己实际操作去掉index.php的过程. 1.要修改Apache ...
- Apache中 RewriteRule 规则参数介绍
Apache中 RewriteRule 规则参数介绍 摘要: Apache模块 mod_rewrite 提供了一个基于正则表达式分析器的重写引擎来实时重写URL请求.它支持每个完整规则可以拥有不限数量 ...
- 修改apache配置文件去除thinkphp url中的index.php
例如你的原路径是 http://localhost/test/index.php/index/add那么现在的地址是 http://localhost/test/index/add如何去掉index. ...
- php CI 实战教程:如何去掉index.php目录
Windows下自由创建.htaccess文件的N种方法 .htaccess是apache的访问控制文件,apache中httpd.conf的选项配合此文件,完美实现了目录.站点的访问控制,当然最多的 ...
- ci框架url去掉index.php
去掉index.php: 1.修改配置文件, $config['index_page'] = ' '; 设置空 2.修改Apache,搜索 htaccess 将 AllowOverride None ...
- 修改apache配置文件去除thinkphp url中的index.php(转)
例如你的原路径是 http://localhost/test/index.php/index/add那么现在的地址是 http://localhost/test/index/add如何去掉index. ...
- IIS7以上版本去掉伪静态去掉index.php方法
1,由于从iis7以上的版本httpd.ini文件已不会被解析,将以下的xml文件复制到web.config 的文件中,然后放到网站的根目录即可. <?xml version="1.0 ...
随机推荐
- Xposed出现 java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
Xposed出现 java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implem ...
- decimal类型不能为空,自定义update更新null值的问题。
if (!string.IsNullOrEmpty(yt_time_limit_1)) { entity["yt_time_limit_1"] = Convert.ToDecima ...
- intellj idea 如何设置类头注释和方法注释
intellj idea 如何设置类头注释和方法注释 intellj idea的强大之处就不多说了,相信每个用过它的人都会体会到,但是我们也会被他的复杂搞的晕头转向,尤其刚从ecl ...
- java之适配器模式
interface Window { public void open(); public void close(); public void activated(); ...
- hdu 1823 Luck and Love 二维线段树
题目链接 很裸的题, 唯一需要注意的就是询问时给出的区间并不是l<r, 需要判断然后交换一下, WA了好多发... #include<bits/stdc++.h> using nam ...
- 【LeetCode题意分析&解答】36. Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...
- 批量添加target属性
<script> addTarget(); function addTarget(){ var oa=document.getElementsByTagName('a'); for(var ...
- 转: angular编码风格指南
After reading Google's AngularJS guidelines, I felt they were a little too incomplete and also guide ...
- 网页解析不了PHP源代码的解决方法
一般出现这个错误都是因为修改了apache配置文件,但是没有使apache配置生效. 所以只要执行以下命令就行了: sudo apachectl restart sudo apachectl grac ...
- android程序启动画面之Splash总结[转]
方法一: 很多应用都会有一个启动界面.欢迎画面慢慢隐现,然后慢慢消隐.实现这种效果的方法有两种(暂时只发现两种)1.使用两个Activity,程序启动时候load第一张Activity,然后由tick ...