回答編集履歴

1

追記:検証を追記

2019/11/21 00:32

投稿

Y.H.
Y.H.

スコア7914

test CHANGED
@@ -7,3 +7,113 @@
7
7
  RewriteCond %{REQUEST_URI} !^/fuga/
8
8
 
9
9
  ```
10
+
11
+
12
+
13
+ 検証
14
+
15
+ ```bash
16
+
17
+ $ cat /var/www/html/.htaccess
18
+
19
+ RewriteEngine On
20
+
21
+ RewriteBase /
22
+
23
+
24
+
25
+ RewriteCond %{HTTP_HOST} ^hoge.example.jp$
26
+
27
+ RewriteCond %{REQUEST_URI} !^/fuga/
28
+
29
+ RewriteRule ^(.*)$ http://example.jp/$1 [R=301,L]
30
+
31
+
32
+
33
+ $ telnet localhost 80
34
+
35
+ Trying 127.0.0.1...
36
+
37
+ Connected to localhost.
38
+
39
+ Escape character is '^]'.
40
+
41
+ HEAD / HTTP/1.1
42
+
43
+ Host: hoge.example.jp
44
+
45
+
46
+
47
+ HTTP/1.1 301 Moved Permanently
48
+
49
+ Date: Thu, 21 Nov 2019 00:28:21 GMT
50
+
51
+ Server: Apache/2.4.29 (Ubuntu)
52
+
53
+ Location: http://example.jp/
54
+
55
+ Content-Type: text/html; charset=iso-8859-1
56
+
57
+
58
+
59
+ $ telnet localhost 80
60
+
61
+ Trying 127.0.0.1...
62
+
63
+ Connected to localhost.
64
+
65
+ Escape character is '^]'.
66
+
67
+ HEAD /fuga/ HTTP/1.1
68
+
69
+ Host: hoge.example.jp
70
+
71
+
72
+
73
+ HTTP/1.1 200 OK
74
+
75
+ Date: Thu, 21 Nov 2019 00:28:07 GMT
76
+
77
+ Server: Apache/2.4.29 (Ubuntu)
78
+
79
+ Last-Modified: Thu, 21 Nov 2019 00:18:51 GMT
80
+
81
+ ETag: "4a-597d03de5b952"
82
+
83
+ Accept-Ranges: bytes
84
+
85
+ Content-Length: 74
86
+
87
+ Vary: Accept-Encoding
88
+
89
+ Content-Type: text/html
90
+
91
+
92
+
93
+ $ telnet localhost 80
94
+
95
+ Trying 127.0.0.1...
96
+
97
+ Connected to localhost.
98
+
99
+ Escape character is '^]'.
100
+
101
+ HEAD /fuga/fuga.html HTTP/1.1
102
+
103
+ Host: hoge.example.jp
104
+
105
+
106
+
107
+ HTTP/1.1 404 Not Found
108
+
109
+ Date: Thu, 21 Nov 2019 00:29:12 GMT
110
+
111
+ Server: Apache/2.4.29 (Ubuntu)
112
+
113
+ Content-Type: text/html; charset=iso-8859-1
114
+
115
+
116
+
117
+ $
118
+
119
+ ```