.htaccess拒绝除索引外的所有php文件

.htaccess拒绝除索引外的所有php文件,php,apache,.htaccess,Php,Apache,.htaccess,我有一个.htaccess文件,其中包含以下内容: <IfModule mod_rewrite.c> RewriteEngine on SetEnv HTTP_MOD_REWRITE on RewriteBase /wsproject/ Options All -Indexes DirectoryIndex index.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond

我有一个.htaccess文件,其中包含以下内容:

<IfModule mod_rewrite.c>  
    RewriteEngine on
    SetEnv HTTP_MOD_REWRITE on
    RewriteBase /wsproject/

    Options All -Indexes
    DirectoryIndex index.php

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>

重新启动发动机
SetEnv HTTP_MOD_重写
重写基础/WSBASE项目/
选项所有-索引
DirectoryIndex.php
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-L
重写规则^(+)$index.php?url=$1[QSA,L]
我想对用户隐藏所有内容:目录结构和私有文件,同时启用公共文件:*.js、*.html、*.css、*.swf、*.jpg和其他内容。我希望.php文件只能从文件系统访问,除了根目录中的index.php

我只想通过HTTP提供请求,HTTP是用一个(抽象的)MVC URL模式编写的,比如:
www.domain.com/lang/controller\u name/action\u name/arg1/arg2///argn
,它们被.htaccess和public*.html、*.js……等文件重写

虽然
Options All-Indexes
隐藏了文件列表,但它不会阻止提供不需要的请求,例如:
www.domain.com/library/Bootstrap.php
。 而删除/注释掉
RewriteCond%{REQUEST_FILENAME}-f
可以解决这个问题,但在这种情况下,我的public.html、.css、.js…等文件都不会被提供

我尝试对每个php文件(index.php除外)应用all的Deny,但总是收到500条内部服务器错误消息。我在本地主机上,在windows上这样做


有什么想法吗?

不要说除了现有文件以外的所有文件都应该指向index.php,你可以说除了*.js、*.html、*.css、*.swf、*.jpg之外的所有文件都应该指向index.php

这与否认并不完全相同,因为你没有给出禁止的回答。虽然在这种情况下,您不会给出关于哪些文件存在或不存在的任何信息,所以我认为这是一个更好的解决方案

<IfModule mod_rewrite.c>  
    RewriteEngine on
    SetEnv HTTP_MOD_REWRITE on
    RewriteBase /wsproject/

    Options All -Indexes
    DirectoryIndex index.php

    RewriteRule \.(js|html|css|swf|jpg)(\?|$) - [QSA,L]
    RewriteRule ^index.php(\?|$) - [QSA,L]
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>

重新启动发动机
SetEnv HTTP_MOD_重写
重写基础/WSBASE项目/
选项所有-索引
DirectoryIndex.php
重写规则\(js | html | css | swf | jpg)(\?|$)-[QSA,L]
重写规则^index.php(\?|$)-[QSA,L]
重写规则^(+)$index.php?url=$1[QSA,L]
请注意,重写到
-
,意味着根本不进行任何重写。

我建议使用
chmod
命令修改文件的读/写/可执行性值,而不是(或者)编辑.htaccess文件


对于
chmod
是/做什么,可以找到一个相对简洁和合理的解释,但通常最简单的方法是
chmod 644
您的文件和
chmod 755
您的文件夹

当上述解决方案不起作用时,这对我来说效果很好——对那些尝试过它的人做了一些轻微的修改:如果不需要RewriteBase,请删除它,如果需要,为文件夹/文件添加一些额外的RewriteRule例外,如:
RewriteRule^administrator-[QSA,L]
RewriteRule\(js | html | css | swf | jpg | ico | eot | woff | ttf | svg)(\?$)-[QSA,L]