阻止查看某些 .php 文件
我将 PHP 与 Apache 结合使用,并使用漂亮的 URL 与 mod_rewrite 结合使用。
我有一个 index.php
,其中包含一些包含内容的其他 .php 文件。
现在我想阻止人们查看这些(仅内容).php 文件,除非它们是通过我的 index.php
脚本包含的。
这是我正在使用的重写规则:RewriteRule ^/?([a-zA-Z0-9/-]+)/?$ /index.php [NC,L]
它将每个请求重写到处理请求的index.php并包含相应的内容。
有没有办法用mod_rewrite
(即我的.htaccess
)来做到这一点?通常拒绝访问 .php 文件或类似的文件?
谢谢!
I'm using PHP with Apache and pretty URLs with mod_rewrite.
I have an index.php
where I include some other .php files that contain the content.
Now I'd like to prevent people from viewing those (content only) .php files, unless they are included via my index.php
script of course.
This is the RewriteRule I'm using:RewriteRule ^/?([a-zA-Z0-9/-]+)/?$ /index.php [NC,L]
It rewrites every request to the index.php where requests are handled and content is included accordingly.
Is there a way to do this with mod_rewrite
, i.e. my .htaccess
? To generally deny access to .php files or something like that?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在索引文件中放入一个常量,然后在每个 php 文件中执行以下操作:
Put a constant in you index file and then in each php file do something like:
将 PHP 文件(index.php 除外)保留在 Web 根目录之外。您仍然可以在代码中包含/要求它们,但人们将无法通过 URL 访问它们。
Keep your PHP files (except index.php) out of the web root. You can still include/require them from your code, but people won't be able to access them by URL.
<罢工>
如果所有请求都重写到index.php,那么当前如何访问这些文件?您不需要拒绝访问。
使用
和处理 PHP 中的其他所有内容。
How do you access these files currently if all requests are rewritten to index.php? You should not need to deny access.
Use
and handle everything else in PHP.