1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

htaccess mod_rewriteで403発生【URLに半角スペースがある場合】

Posted at

URL内に「%20(半角スペース)」が含まれていると403エラーが発生します。
1.まずURL内に「%20」があると→403エラー発生。
2.「whoami20230614 a.php」など半角スペースが含まれた実在ファイルに直アクセス→200OK
3.「?」マーク以降に「%20」があるとき(クエリーパラメーター扱い?)→200OK
4.「/detail_history/?/iuid=314/ab%20cd/?a=12%2134?xyz=1%202」など第一セグメントの後ろに「?/」をつけてアクセス→200OK
5.「%21(!ビックリマーク)」では発生しない。
4の補足
http://xxx2019.ce99.net/detail_history/iuid=314/ab%20cd/?a=12%2134?xyz=1%202👈403
http://xxx2019.ce99.net/detail_history/?/iuid=314/ab%20cd/?a=12%2134?xyz=1%202👈200

ブラウザからページ確認。
※ステータスが403であることも確認する。

Forbidden
You don't have permission to access this resource.

シェル端末からエラーlogを確認。
/home/myproject/logs/httpd/error_log.20230626

[opc@0206oci_opewebstaging httpd]$ cat /home/myproject/logs/httpd/error_log.20230626
[Mon Jun 26 19:42:50.143089 2023] [rewrite:error] [pid 2609218] [client 113.35.72.50:62987] AH10411: Rewritten query string contains control characters or spaces
[Mon Jun 26 19:45:00.058456 2023] [rewrite:error] [pid 3110208] [client 113.35.72.50:62899] AH10411: Rewritten query string contains control characters or spaces

/etc/httpd/conf/extra/my_httpd.conf

  RewriteRule ^(.+)$ index.php?$1
#↓末尾に「 [B]」を追加する。
  RewriteRule ^(.+)$ index.php?$1 [B]
#httpdを再起動の上、動作確認をお忘れなく…。

参考にしたURL
【.htaccess】mod_rewrite モジュール – その 5 RewriteRule のフラグ一覧
https://www.google.com/amp/s/web.hazu.jp/htaccess-rewriterule/amp/
htaccess 301リダイレクト【URLに半角スペースがある場合】
https://monostyle.net/investment/htaccess.html

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?