0

作成する Web ページ用に独自の MVC スタイル システムを開発しています。ファイル構造は次のとおりです。

docs/contact/contact.php
img/
inc/
index.php
.htaccess

Docs 内には、Web サイトの各セクションのフォルダーがあります。この場合、「連絡先」を展開しました。.htaccess ファイルはすべての URI を index.php にルーティングしますが、それらが直接アクセスされる場合、つまり domain.com/docs/contact/contact.php にはルーティングされません。

これは私の .htaccess です:

Options +FollowSymlinks
RewriteEngine on
RewriteOptions MaxRedirects=10

AddType "text/html; charset=UTF-8" html 
AddType "text/plain; charset=UTF-8" txt

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

# if file not exists
RewriteCond %{REQUEST_FILENAME} !-f

# if dir not exists
RewriteCond %{REQUEST_FILENAME} !-d

# avoid 404s of missing assets in our script
RewriteCond %{REQUEST_URI} !^.*\.(jpe?g|png|gif|css|js)$ [NC]

RewriteRule .* index.php [QSA,L]

</IfModule>

ファイル index.php から直接呼び出されない限り、人々が docs フォルダ内のファイルにアクセスできないようにする方法はありますか? これは .htaccess で実行できますか?

4

1 に答える 1

0

これを防ぐために、index.phpで何かを定義できます。

define('MyAppLoaded', true);

そして、他のファイルで以下を確認してください:

if (!defined('MyAppLoaded')) {
    // show message or handle direct access
}

しかし、本当の問題は、そもそもファイルに直接アクセスしたくないのに、なぜこれらすべてのファイルをdocrootに配置するのかということです。

docroot内の唯一のphpファイルは、次の内容のindex.phpファイルである必要があります。

<?php

require __DIR__ . '/../bootstrap.php';
于 2013-02-15T11:37:23.853 に答える