teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

再現方法の追記

2020/07/23 10:56

投稿

yuzusan
yuzusan

スコア7

title CHANGED
@@ -1,1 +1,1 @@
1
- htaccess Rewrite使おうとするがエラーが発生する
1
+ .htaccess RewriteRule記入しURLを省略しようとするも、思い通りに動作しない
body CHANGED
@@ -5,25 +5,24 @@
5
5
  ブラウザ上の表示URL(例)
6
6
  example.com/yamada/
7
7
  example.com/suzuki/profile.jpg
8
- example.com/takahashi/myinfo/address.php
9
8
 
10
9
  実際にアクセスしているURL
11
10
  example.com/name/yamada/
12
11
  example.com/name/suzuki/profile.jpg
13
- example.com/name/takahashi/myinfo/address.php
14
12
 
15
13
  ### やったこと
14
+ ※ブラウザのキャッシュはきちんと削除しています
16
15
  ```htaccess
17
16
  RewriteEngine On
18
17
  RewriteCond %{REQUEST_FILENAME} !-f
19
18
  RewriteCond %{REQUEST_FILENAME} !-d
20
19
  RewriteCond %{REQUEST_URL} !^/name/
21
- RewriteRule ^(.*)$ /name/$1`
20
+ RewriteRule ^(.*)$ /name/$1
22
21
  ```
23
22
  ① example.com/yamada/ にアクセス
24
23
  → ブラウザに表示されるURLが example.com/name/yamada/ となってしまい name が表示されてしまう。ですが内容はきちんと表示されます。
24
+ name は表示させないようにしたい。
25
25
 
26
-
27
26
  ② example.com/yama/ にアクセス(存在しないフォルダ)
28
27
  → Internal Server Errorになってしまい、error.logを見ると以下のようになっていて、
29
28
  ```log
@@ -65,21 +64,71 @@
65
64
  RewriteCond %{REQUEST_URL} !^/name/
66
65
  ```
67
66
  このようにしているのに大量のエラーが発生していて name という文字をつけて繰り返しアクセスを試みていると思われます。(初心者なのでよくわかりませんが...)
68
- htaccessがいけないのかサーバー側の設定がいけないのか分かりませんが、原因がわかる方に教えていただきたいです。
67
+ htaccessがいけないのかapache2.confの設定がいけないのか分かりませんが、原因がわかる方に教えていただきたいです。
69
68
 
70
69
  ### 環境
71
- サーバー:RaspberryPi
70
+ サーバー:Debian Buster with Raspberry Pi Desktop (Oracle VM VirtualBox仮想環境)
72
- 自宅サーバーなので設定変更はなんでもできます。
73
71
  apache:2.4.38(Debian)
74
72
  php:7.3.14
75
73
 
76
74
  apache2.confの一部です。
77
75
  ```
78
76
  <Directory /var/www/>
79
- Options Includes FollowSymLinks
77
+ Options FollowSymLinks
80
78
  AllowOverride All
81
79
  Require all granted
82
- AddType text/html .html
83
- AddOutputFilter INCLUDES .html
84
80
  </Directory>
85
- ```
81
+ ```
82
+ ### 環境(詳細)
83
+ "ブラウザに表示されるURLが example.com/name/yamada/ となってしまう"というのは、あり得ない
84
+ と指摘されましたが、どうしても name が表示されてしまいます。
85
+ 時間のある方は全く同じ環境を再現して頂きたいです。
86
+
87
+ ・用意するもの
88
+ - 仮想で動かすソフト(Oracle VM VirtualBox など)
89
+ [Oracle VM VirtualBox](https://www.oracle.com/technetwork/jp/server-storage/virtualbox/overview/index.html)
90
+ - DebianのISO
91
+ [Raspberry Pi Desktop](https://www.raspberrypi.org/downloads/raspberry-pi-desktop/)
92
+
93
+ ・手順
94
+ OSインストール完了までは省略します。
95
+ 難しいことは書きません。以下をコピペで再現できると思います。
96
+ ```ssh
97
+ sudo apt-get update
98
+ sudo apt-get install apache2
99
+ sudo nano /etc/apache2/apache2.conf
100
+ ```
101
+ 編集
102
+ ```
103
+ <Directory /var/www/>
104
+ Options FollowSymLinks
105
+ AllowOverride All
106
+ Require all granted
107
+ </Directory>
108
+ ```
109
+ 一番下に追記
110
+ ```
111
+ LoadModule include_module modules/mod_include.so
112
+ ```
113
+ Ctrl + O で上書き
114
+ Ctrl + X で閉じる
115
+ ```ssh
116
+ sudo cp -r /usr/lib/apache2/modules /etc/apache2/modules
117
+ sudo a2enmod rewrite
118
+ sudo service apache2 restart
119
+ cd /var/www/html
120
+ sudo mkdir name
121
+ cd name
122
+ sudo mkdir yamada
123
+ sudo nano index.html
124
+ ```
125
+ ```
126
+ <p>山田</p>
127
+ ```
128
+ 上書き&閉じる
129
+ ------設定完了------
130
+ 同じネットワーク内からブラウザで
131
+ http://[IPアドレス]/yamada
132
+ にアクセスしても
133
+ http://[IPアドレス]/name/yamada
134
+ になると思います。

4

書式を大幅に変更しました。ログ内容を追記しました。

2020/07/23 10:55

投稿

yuzusan
yuzusan

スコア7

title CHANGED
@@ -1,1 +1,1 @@
1
- htaccessを使いディレクトリの一部を省略しアクセスできるよする
1
+ htaccess Rewriteを使するがエラーが発生する
body CHANGED
@@ -1,66 +1,71 @@
1
1
  ### やりたいこと
2
- ディレクトリの一部を省略しアクセスする
2
+ ディレクトリの一部を省略しアクセスする
3
+ ・ブラウザ表示上のURLは変えない
3
4
 
4
5
  ブラウザ上の表示URL(例)
5
- example.com/sato/
6
+ example.com/yamada/
6
7
  example.com/suzuki/profile.jpg
7
8
  example.com/takahashi/myinfo/address.php
8
9
 
9
10
  実際にアクセスしているURL
10
- example.com/name/sato/
11
+ example.com/name/yamada/
11
12
  example.com/name/suzuki/profile.jpg
12
13
  example.com/name/takahashi/myinfo/address.php
13
14
 
14
- 実際にアクセスしているフォルダーの name を省略したい。
15
-
16
- nameディレクトリ以外の実際に存在するファイルに対しては通常通りアクセスしたいです。
17
- サーバー上に複数のファイルやフォルダーがあり、RewriteCond (?)を使い除外するファルダをすべて書くことはほぼ不可能です。
18
-
19
- 実際にアクセスしたURLやnameをつけたURLにアクセスしようとしても存在しなかった場合は、404 not foundを返したいです。
20
-
21
- ### 参考にしがうまく動作せず
15
+ ### やっこと
22
- https://teratail.com/questions/67475
23
- こちらを参考にやってみましたがうまく動作しません。
24
-
25
- 試したこと①
26
- example.com/sato/
27
16
  ```htaccess
28
- RewriteEngine on
29
- RewriteRule name/(.*) $1 [R=301]
30
- ```
31
- 404 Not Found になります。
32
- access.logを見てもアクセス先は /sato/ になっています。
33
-
34
- 試したこと② 回答ありがとうございます。
35
- example.com/sato/
36
- ```htaccess
37
- RewriteEngine on
38
- RewriteBase /
39
- RewriteCond %{REQUEST_URI} !(^/name$)
40
- RewriteRule ^(.*)$ /name/$1 [R=301,L]
41
- ```
42
- リダイレクトが繰り返し行われてしまいます。
43
- ブラウザ表示上のURLは example.com/name/name/name/name/name/name(省略・・・)/sato/ になります。
44
- 編集内容 htaccess 3行目、 (^/name$)を(^/name/$)にしましたが状況は変わらず。
45
-
46
- 試したこと③ 回答ありがとうございます。
47
- ```htaccess
48
17
  RewriteEngine On
49
18
  RewriteCond %{REQUEST_FILENAME} !-f
50
19
  RewriteCond %{REQUEST_FILENAME} !-d
51
20
  RewriteCond %{REQUEST_URL} !^/name/
52
- RewriteRule ^(.*)$ /name/$1
21
+ RewriteRule ^(.*)$ /name/$1`
53
22
  ```
54
- example.com/sato/ にアクセスした場合
23
+ ① example.com/yamada/ にアクセス
55
- ブラウザ表示上のURL example.com/name/sato/ ます。
24
+ → ブラウザ表示されるURL example.com/name/yamada/ ってしい name が表示されてしまう。でが内容はきちんと表示されます
56
- やりたい事と似ていますが、 name が表示されてしまいます。
57
25
 
26
+
58
- example.com/SATO/
27
+ ② example.com/yama/ にアクセス(存在しないフォルダ)
59
- example.com/satooo/ にアクセスした場合、Internal Server Errorが発生します。
28
+  Internal Server Errorになってしまい、error.logを見ると以下のようになっていて、
60
- nameディレクトリ以外の実際に存在するファイルにアクセスした場合は、正しくアクセスできます。
61
29
  ```log
62
- AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
30
+ [Sat Jun 06 10:39:55.690590 2020] [core:error] [pid 1398] [client 192.168.10.101:50114] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
63
31
  ```
32
+ 'LogLevel debug' debugの状態でlogを見ると、
33
+ ```log
34
+ [Sat Jun 06 11:04:25.664214 2020] [authz_core:debug] [pid 1567] mod_authz_core.c(820): [client 192.168.10.101:50387] AH01626: authorization result of Require all granted: granted
35
+ [Sat Jun 06 11:04:25.664259 2020] [authz_core:debug] [pid 1567] mod_authz_core.c(820): [client 192.168.10.101:50387] AH01626: authorization result of <RequireAny>: granted
36
+ [Sat Jun 06 11:04:25.664728 2020] [core:error] [pid 1567] [client 192.168.10.101:50387] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
37
+ [Sat Jun 06 11:04:25.664748 2020] [core:debug] [pid 1567] core.c(3833): [client 192.168.10.101:50387] AH00121: r->uri = /name/name/name/name/name/name/name/name/name/name/yama
38
+ [Sat Jun 06 11:04:25.664762 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/name/name/name/name/name/name/yama
39
+ [Sat Jun 06 11:04:25.664775 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/name/name/name/name/name/yama
40
+ [Sat Jun 06 11:04:25.664785 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/name/name/name/name/yama
41
+ [Sat Jun 06 11:04:25.664795 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/name/name/name/yama
42
+ [Sat Jun 06 11:04:25.664805 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/name/name/yama
43
+ [Sat Jun 06 11:04:25.664815 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/name/yama
44
+ [Sat Jun 06 11:04:25.664829 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/yama
45
+ [Sat Jun 06 11:04:25.664842 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/yama
46
+ [Sat Jun 06 11:04:25.664852 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/yama
47
+ [Sat Jun 06 11:04:25.664861 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /yama
48
+ [Sat Jun 06 11:04:25.728630 2020] [authz_core:debug] [pid 1569] mod_authz_core.c(820): [client 192.168.10.101:50388] AH01626: authorization result of Require all granted: granted, referer: http://192.168.10.200/yama
49
+ [Sat Jun 06 11:04:25.728671 2020] [authz_core:debug] [pid 1569] mod_authz_core.c(820): [client 192.168.10.101:50388] AH01626: authorization result of <RequireAny>: granted, referer: http://192.168.10.200/yama
50
+ [Sat Jun 06 11:04:25.729116 2020] [core:error] [pid 1569] [client 192.168.10.101:50388] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://192.168.10.200/yama
51
+ [Sat Jun 06 11:04:25.729131 2020] [core:debug] [pid 1569] core.c(3833): [client 192.168.10.101:50388] AH00121: r->uri = /name/name/name/name/name/name/name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama
52
+ [Sat Jun 06 11:04:25.729141 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/name/name/name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama
53
+ [Sat Jun 06 11:04:25.729151 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/name/name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama
54
+ [Sat Jun 06 11:04:25.729161 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama
55
+ [Sat Jun 06 11:04:25.729171 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama
56
+ [Sat Jun 06 11:04:25.729180 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama
57
+ [Sat Jun 06 11:04:25.729190 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama
58
+ [Sat Jun 06 11:04:25.729199 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/favicon.ico, referer: http://192.168.10.200/yama
59
+ [Sat Jun 06 11:04:25.729208 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/favicon.ico, referer: http://192.168.10.200/yama
60
+ [Sat Jun 06 11:04:25.729218 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/favicon.ico, referer: http://192.168.10.200/yama
61
+ [Sat Jun 06 11:04:25.729227 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /favicon.ico, referer: http://192.168.10.200/yama
62
+ ```
63
+ htaccessで
64
+ ```htaccess
65
+ RewriteCond %{REQUEST_URL} !^/name/
66
+ ```
67
+ このようにしているのに大量のエラーが発生していて name という文字をつけて繰り返しアクセスを試みていると思われます。(初心者なのでよくわかりませんが...)
68
+ htaccessがいけないのかサーバー側の設定がいけないのか分かりませんが、原因がわかる方に教えていただきたいです。
64
69
 
65
70
  ### 環境
66
71
  サーバー:RaspberryPi

3

ご回答に対しての追記

2020/06/06 02:22

投稿

yuzusan
yuzusan

スコア7

title CHANGED
File without changes
body CHANGED
@@ -31,7 +31,7 @@
31
31
  404 Not Found になります。
32
32
  access.logを見てもアクセス先は /sato/ になっています。
33
33
 
34
- 試したこと②
34
+ 試したこと② 回答ありがとうございます。
35
35
  example.com/sato/
36
36
  ```htaccess
37
37
  RewriteEngine on
@@ -41,14 +41,27 @@
41
41
  ```
42
42
  リダイレクトが繰り返し行われてしまいます。
43
43
  ブラウザ表示上のURLは example.com/name/name/name/name/name/name(省略・・・)/sato/ になります。
44
+ 編集内容 htaccess 3行目、 (^/name$)を(^/name/$)にしましたが状況は変わらず。
44
45
 
45
- 試したこと③
46
- Internal Server Errorと表示されています。
46
+ たこと③ 回答ありがとうございます。
47
- ```ここに言語を入力
47
+ ```htaccess
48
+ RewriteEngine On
49
+ RewriteCond %{REQUEST_FILENAME} !-f
50
+ RewriteCond %{REQUEST_FILENAME} !-d
48
- Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace_
51
+ RewriteCond %{REQUEST_URL} !^/name/
52
+ RewriteRule ^(.*)$ /name/$1
49
53
  ```
54
+ example.com/sato/ にアクセスした場合
55
+ ブラウザ表示上のURLは example.com/name/sato/ になります。
50
- htaccessに記載し内容は忘れしたが、このようなエラー出る場合もあります。
56
+ やりい事と似ていが、 name 表示されてしいます。
51
57
 
58
+ example.com/SATO/
59
+ example.com/satooo/ にアクセスした場合、Internal Server Errorが発生します。
60
+ nameディレクトリ以外の実際に存在するファイルにアクセスした場合は、正しくアクセスできます。
61
+ ```log
62
+ AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
63
+ ```
64
+
52
65
  ### 環境
53
66
  サーバー:RaspberryPi
54
67
  自宅サーバーなので設定変更はなんでもできます。

2

追記、内容の改善をしました。

2020/06/04 11:47

投稿

yuzusan
yuzusan

スコア7

title CHANGED
File without changes
body CHANGED
@@ -36,7 +36,7 @@
36
36
  ```htaccess
37
37
  RewriteEngine on
38
38
  RewriteBase /
39
- RewriteCond %{REQUEST_URI} !(^/guild$)
39
+ RewriteCond %{REQUEST_URI} !(^/name$)
40
40
  RewriteRule ^(.*)$ /name/$1 [R=301,L]
41
41
  ```
42
42
  リダイレクトが繰り返し行われてしまいます。

1

追記、内容の改善をしました。

2020/06/04 10:48

投稿

yuzusan
yuzusan

スコア7

title CHANGED
File without changes
body CHANGED
@@ -21,14 +21,47 @@
21
21
  ### 参考にしたがうまく動作せず
22
22
  https://teratail.com/questions/67475
23
23
  こちらを参考にやってみましたがうまく動作しません。
24
+
25
+ 試したこと①
26
+ example.com/sato/
27
+ ```htaccess
28
+ RewriteEngine on
29
+ RewriteRule name/(.*) $1 [R=301]
30
+ ```
31
+ 404 Not Found になります。
32
+ access.logを見てもアクセス先は /sato/ になっています。
33
+
34
+ 試したこと②
35
+ example.com/sato/
36
+ ```htaccess
37
+ RewriteEngine on
38
+ RewriteBase /
39
+ RewriteCond %{REQUEST_URI} !(^/guild$)
40
+ RewriteRule ^(.*)$ /name/$1 [R=301,L]
41
+ ```
42
+ リダイレクトが繰り返し行われてしまいます。
43
+ ブラウザ表示上のURLは example.com/name/name/name/name/name/name(省略・・・)/sato/ になります。
44
+
45
+ 試したこと③
24
- Internal Server Errorと表示されてしまいます
46
+ Internal Server Errorと表示されてしまいます
25
47
  ```ここに言語を入力
26
48
  Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace_
27
49
  ```
50
+ htaccessに記載した内容は忘れましたが、このようなエラーが出る場合もあります。
28
51
 
29
52
  ### 環境
30
53
  サーバー:RaspberryPi
54
+ 自宅サーバーなので設定変更はなんでもできます。
31
55
  apache:2.4.38(Debian)
32
56
  php:7.3.14
33
57
 
34
- 自宅サーバーなので設定変更はなんでもできます。
58
+ apache2.conf一部です。
59
+ ```
60
+ <Directory /var/www/>
61
+ Options Includes FollowSymLinks
62
+ AllowOverride All
63
+ Require all granted
64
+ AddType text/html .html
65
+ AddOutputFilter INCLUDES .html
66
+ </Directory>
67
+ ```