問題描述
例如: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.
我在根文件夾中有文件:內容.php關于.php頁腳.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 文件的訪問?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!