如何使用mod_rewrite忽略对php文件的访问? [英] How to ignore access to php files with mod_rewrite?
问题描述
例如: www.example.com/about.php
For example: www.example.com/about.php
我不希望使用扩展名为.php的文件,而是显示404页面.
I don't want the files with the extension .php to be available to reach, display a 404 page instead.
我的文件位于根文件夹中: content.php about.php footer.php 等等... 现在,我可以通过输入地址栏来访问这些文件.我想限制这个.
I have the files in the root folder: content.php about.php footer.php etc... Now i can reach these files by typing in to the adress bar. I want to restrict this.
我该怎么做?
推荐答案
一种避免mod_rewrite的开销和复杂性的更好方法是简单地将不需要的URL不需要的文件放在根文件夹中.您可以将它们放在其他位置,然后从那里包含它们.简单和(更)安全,但是出于某种原因,这似乎不是常识.
A better approach that avoids the overhead and complexity of mod_rewrite is to simply not put files you don't want reached by url in the root folder. You can just put them somewhere else and include them from there; simple and (more) secure, but for some reason this doesn't seem to be common knowledge.
示例结构可能是
project/
project/root
project/lib
您的公共代码(例如index.php)将存在于项目/根目录中,并且将是网站的根目录.您所包含的代码将存在于project/lib中,可以使用require,include等轻松地将其包含在内.
Your public code (e.g. index.php) would live in project/root, and that would be the website root. Your included code would live in project/lib can be easily included using require, include, etc.
无mod_rewrite.很简单.
No mod_rewrite. Very simple.
这篇关于如何使用mod_rewrite忽略对php文件的访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!