Help us understand the problem. What is going on with this article?

mod_rewriteで、存在しないファイルへのリクエストに404を返す

More than 1 year has passed since last update.

表示するページの一部の画像がない場合、mod_rewriteで404を返してみる

RewriteEngine On
RewriteCond %{REQUEST_URI} ^.*(\.jpg|\.jpeg|\.png)$ #拡張子が画像の場合
RewriteCond %{REQUEST_FILENAME} !-f #ファイルが存在しない場合
RewriteRule ^.*$ - [NC,R=404,L]
オプション
NC 大文字小文字を区別しない
R=404 ステータスコードを404に変更
L 条件にマッチしてURLを書き換えた場合、ここで書き換えを終了する(これより後の条件は無視される)
  • RewriteCond の条件は正規表現で指定する
  • RewriteCond は複数行書いた場合、AND の条件になる
  • OR の条件にしたい場合は、RewriteCond %{REQUEST_URI} ^.*(\.jpg|\.jpeg|\.png)$ [OR] のように最後に [OR] を付ける
  • オプションはカンマ区切りで複数指定可能
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした