codeigniter的URL重写问题 [英] Codeigniter's URL Rewriting Problem

查看:261
本文介绍了codeigniter的URL重写问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的的htaccess 脚本,这样我可以隐藏的的index.php URI

I’ve using the following htaccess script so that i can hide index.php from the uri.

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

但我面临的主要问题:(

But i’ve facing a major problem :(

我有一个名为资产我旁边的的index.php 文件目录,它应该在那里。 现在,当我浏览目录由浏览器那么codeigniter的未找到页显示。 我不能浏览文件的 /assets/image.jpg ,但它显示,当我从&LT叫它; IMG> 标记

I’ve a directory named assets beside my index.php file and it should be there. Now when i browse the directory by browser then the codeigniter’s not found page displays. I can’t browser the file /assets/image.jpg but it displays when i call it from an <img> tag

现在我该怎么办?

请注意,这是工作在我的本地服务器(本地),但不是在活的服务器。

Note that it is working in my local server (localhost) but not in the live server.

推荐答案

你们是一路过来想这一点。

You guys are way over thinking this.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /index.php/$1 [NC,L]

这将传递阿帕奇将不利于脱至codeIgniter任何请求。这样,你可以自由各地创建目录没有更新您的重写规则,你不需要设置404处理在Apache中(甚至在图像/资源目录)。

That'll pass any request that Apache wouldn't serve off to CodeIgniter. This way you're free to create directories all over without updating your rewrite rules, and you don't need to setup 404 handling in Apache (even inside your image/resource directories).

幸得Zend框架笔者推荐在他们的用户指南该位。这一版本稍微修改为codeIgniter。

Credit goes to the Zend Framework authors that recommend this bit in their user guide. This version is slightly modified for CodeIgniter.

这篇关于codeigniter的URL重写问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆