Codeigniter的URL重写 [英] Codeigniter's URL Rewriting

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

问题描述

我正在使用以下 htaccess 脚本,以便可以从URI隐藏 index.php

I'm 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'm facing a major problem :(

I在我的 index.php 文件旁边有一个名为 assets 的目录,它应该在该目录中。 ,然后显示Codeigniter的未找到页面。我无法浏览文件 /assets/image.jpg ,但是当我从< img> 标签

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

我现在能做什么?

请注意,它正在我的本地服务器( localhost )中工作,但不在实时服务器中工作。

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

推荐答案

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]

这会将Apache不提供服务的任何请求传递给CodeIgniter。这样,您就可以在不更新重写规则的情况下自由地创建目录,并且无需在Apache中设置404处理(甚至在图像/资源目录内部)。

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).

Credit提供给Zend Framework作者,他们在其用户指南中推荐了这一点。此版本已为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天全站免登陆