0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

URLクエリパラメータ付きアクセスを禁止/許可する方法《.htaccess》

Last updated at Posted at 2025-10-27

はじめに

.htaccessを使って、URLクエリパラメータ(クエリ)がついたアクセス禁止/許可する方法をまとめました。

《URLクエリパラメータ(クエリ)とは?》
URLの ? 以降の文字列のこと
[例:https[:]//example.com/search?q=aaaaaaaaaa

URLクエリパラメータ付きアクセスを禁止する.htaccess

.htaccess (クエリ禁止)
<RequireAll>
Require all granted
Require not expr "!(%{QUERY_STRING} == '')"
</RequireAll>

《解説》
Require all granted]全てのアクセス許可
Require not]アクセス禁止
expr]条件
!]ではない場合
%{QUERY_STRING} == '']クエリが空

『クエリが空』ではない場合(=クエリがある場合)はアクセス禁止

URLクエリパラメータ付きアクセスを許可する.htaccess

.htaccess (クエリ許可)
<RequireAll>
Require expr "!(%{QUERY_STRING} == '') || (%{QUERY_STRING} == '')"
</RequireAll>

《解説》
Require]アクセス許可
expr]条件
!(%{QUERY_STRING} == '')]クエリが空ではない
||]または
(%{QUERY_STRING} == '')]クエリが空

『クエリが空ではない場合』または『クエリが空の場合』はアクセス許可

上記.htaccessの使用ケース

上の階層のフォルダではクエリを禁止し、下の階層のフォルダではクエリを許可したい場合などに利用。

(text_sakura)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?