【问题标题】:Hide website service path and its php files from viewing隐藏网站服务路径及其 php 文件不被查看
【发布时间】:2014-07-29 08:07:51
【问题描述】:

我做了很多研究,但仍然找不到解决问题的方法。如果您访问这样的路径,有一个网站可以很容易地显示他的内容:

domain.com/templates/orange/forums/sections/forum_item.php

我不知道如何隐藏所有 /template 目录以防查看。 该站点非常奇怪,通常所有现代系统都具有我在默认配置中需要的功能,但这个没有。 我试图为 /template 做一个 .htaccess 重定向,但显然网站设计已经停止工作 请指教。

【问题讨论】:

  • 您将代码放在更高的文档根目录并为您的应用使用单一入口点
  • 是否限制对/templates URI 的访问?
  • 那么你想保留这个网址domain.com/orange/forums/sections/forum_item.php吗? (刚拿出来/template/

标签: php .htaccess path host


【解决方案1】:

我喜欢将我不想直接访问的任何代码放在document root 和子目录之外。例如,如果您有此设置:

index.php
|_templates/
  |_home.php
  |_about.php
  |_contact.php
|_models/
  |_home.php
  |_about.php
  |_contact.php

我会改为:

|_public_html
  |_index.php
|_templates/
  |_home.php
  |_about.php
  |_contact.php
|_models/
  |_home.php
  |_about.php
  |_contact.php

在这种情况下,不需要更改 apache 配置的文档根目录,但您需要更改包含路径。所以,从 index.php 你可能会做这样的事情:

<?php
include '../models/about.php';
include ../templates/about.php

【讨论】:

    猜你喜欢
    • 2017-02-03
    • 2011-06-01
    • 1970-01-01
    • 2021-01-26
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    相关资源
    最近更新 更多