PHP的mod-rewrite的.htaccess忽略目录 [英] php mod rewrite .htaccess ignore directory

查看:248
本文介绍了PHP的mod-rewrite的.htaccess忽略目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么规则应该怎么设置,使mod_rewrite的忽视公众完全的目录? 通过这一点,我的意思是,这些文件应在它访问,但如果文件不存在,服务器错误页面应该拿出类似,FORBIDDEN或找不到文件什么都。我不需要自定义错误页或类似的东西。我只是希望公共表现得像是没有的mod_rewrite的。

What rule should i set, to make the mod_rewrite ignore the directory "public" completely? By that, I mean, the files should be accessible within it, but if the file does not exist, a server error page should come up with something like, FORBIDDEN, or FILE NOT FOUND what ever. I do not need custom error pages or stuff like that. I simply want the "public" to behave like there is no mod_rewrite at all.

下面是我的.htaccess文件:

Here is my .htaccess file:

RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我的文件结构

My file structure is

/system/
/application/
/public/

我想要的文件夹公众的行为,像有设置完全没有重写规则,完全忽略它。

I want the folder public to behave, like there are no rewrite rules set at all, completely ignore it.

修改

这是我的.htaccess文件:

That's my .htaccess file:

RewriteEngine on

RewriteRule ^(public)($|/) - [L,NC]

RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我已经有这个的.htaccess中/公/文件夹:

I already had this .htaccess in the /public/ folder:

RewriteEngine off

我已经尝试了所有不同的答案以上(一吨从谷歌)。我试图混'举起手来什么那么。

I've tried all the different answers above (and a ton from google). I've tried to mix 'em up what so ever.

我的文件夹:

/system/
/application/
/public/ 
/public/.htaccess #RewriteEngine off
/public/favicon.ico
/index.php

下面是URL与结果我得到:

Below are the url with results I'm getting:

/public/favicon.ico -> I get the favicon
/public/faviDon.ico -> I get the index.php (without mod rewrite you would get "not found")
/public/ -> I get the index.php (without mod rewrite "forbidden")

所以它仍然重写URL,如果没有找到该文件,或在直接访问文件夹。

So it still does rewrite urls, if the file was not found, or upon accessing a folder directly.

你能瑟呢?

非常感谢你的努力的家伙!我真的AP preciate吧!

Thank you very much for effort guys! I really appreciate it!

推荐答案

修改

我完全建立在我的机器上的文件

I completely setup your files on my machine

//  /.htaccess

RewriteEngine on

RewriteRule ^(public)($|/) - [L,NC]

RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

的.htaccess公共文件夹:

.htaccess in the public folder:

//  /public/.htaccess

Options -Indexes
RewriteEngine off

这将禁用重写像你想要的。

This disables rewriting like you wanted.

/public/                 -> 403 Forbidden
/public/favicon.ico      -> 200 File found
/public/not-existing.ext -> 404 File not found

你有没有在你的公共文件夹的index.php? 也许你可以删除,一个..

Do you have a index.php in you public folder? Maybe you could remove that one..

什么样的​​机器上的测试?

What kind of machine your testing on?

我测试了它在Linux + Apache的2 + PHP5.3

I tested it on Linux + Apache 2 + PHP5.3

我可以给你在下午更多的支持(我的时间+2 GMT)

I can give you more support in the afternoon (my time +2 GMT)

编辑2

当我删除了这条线从/.htaccess仍在工作

When I remove this line from /.htaccess is still works

RewriteRule ^(public)($|/) - [L,NC]

一切由的.htaccess中的公用文件夹处理。

Everything is handled by the .htaccess in the public folder.

也许这是在浏览器缓存的问题。尝试不同的浏览器/清除历史记录/安装程序删除缓存。(这取决于浏览器你使用)

Maybe it's a caching problem in your browser. Try a different browser/clean up history/install app to remove cache.. (depending on what browser you're using)

这篇关于PHP的mod-rewrite的.htaccess忽略目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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