ネットで見つけたチュートリアルを使用して、独自の MVC PHP フレームワークを作成しようとしています。しかし、htaccess ファイルの rewrite_mod を理解するのに問題がありました。ここに最初の部分があります:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
1) チュートリアルに書かれているように、これらのルールはすべてのリクエストを public フォルダーにリダイレクトするため、最初の質問はなぜ 2 つのルールがあるのかということです。1番目と2番目の意味。1 つ 2) 2 つ目の部分は、public フォルダー内の別の htaccess ファイルで、以下を含みます。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
2 番目の部分は、url を index.php?url=$1 に書き換えます。この部分は明らかですが、この部分は私には少し難しいです。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
私はそれについて学び、リクエストはファイルまたはディレクトリであってはならないことを伝えますが、index.phpはファイル(パブリックディレクトリ内)です。最後の .htaccess ファイル (パブリック ディレクトリ内) を削除したときに、次のエラーが発生した理由をもう一度質問してください。
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at admin@127.0.0.1 to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
この部分だけを含む htacces しかない場合、うまく機能しますか?
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
本当にありがとう 。