htaccess regax の失敗

htaccess regax の失敗

サーバーへのすべてのリクエストを、リクエスト情報を含む index.php ファイルに移動するようにしています。

また、index.php ファイルに直接アクセスできないようにしたいと思います。

2番目の部分は問題なく動作しますが、何らかの理由で最初の部分が動作しません

  #If the request is for index - prevent from accessing the file directly
    RewriteRule ^(.*)index\.php(.*)$ - [F,L]

#If the request if not for the receiver - redirect to the api server
#RewriteCond !^(*.)campaigns/(\d+)/pictures(.*)$ [NC]
RewriteRule  index.php?request=$1 [NC,QSA,L]

何が間違っているのでしょうか?

答え1

ぱっと見たところ特に目立つ点はありませんでしたが、PHP でこの問題を解決できる場合は、index.php の先頭で次のように操作できます (index.php がサイトのルートにあることを前提としています)。

if ($_SERVER['REQUEST_URI'] == '/index.php' || $_SERVER['REQUEST_URI'] == '/') {
    header('HTTP/1.1 403 Forbidden');
    exit;
}

関連情報