質問編集履歴

2

htaccessの内容をコード表記に修正

2018/04/11 09:47

投稿

rfj
rfj

スコア8

test CHANGED
File without changes
test CHANGED
@@ -38,7 +38,7 @@
38
38
 
39
39
 
40
40
 
41
-
41
+ ```ここに言語を入力
42
42
 
43
43
  PHP_value default_charset none
44
44
 
@@ -341,3 +341,5 @@
341
341
  ExpiresByType text/x-cross-domain-policy "access plus 1 weeks"
342
342
 
343
343
  </IfModule>
344
+
345
+ ```

1

サーバーの環境と.htaccessの内容

2018/04/11 09:47

投稿

rfj
rfj

スコア8

test CHANGED
File without changes
test CHANGED
@@ -23,3 +23,321 @@
23
23
  .htaccessなどで「.php」以降の部分を省いたURLへリダイレクトさせることはできますでしょうか。
24
24
 
25
25
  できれば、不正なURLは阻止しつつ、GET変数でのパラメータ受け取りは行えるようにしたいです。
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+ **【04/11 18:36追記】**
34
+
35
+ サーバーの環境はApache 2.4.20とPHP 7.0.15、PHP 5.6.30です。
36
+
37
+ ルートディレクトリに設置している.htaccessには、以下の内容を記載しています。
38
+
39
+
40
+
41
+
42
+
43
+ PHP_value default_charset none
44
+
45
+ PHP_value output_handler none
46
+
47
+ <IfModule mod_rewrite.c>
48
+
49
+ RewriteEngine on
50
+
51
+
52
+
53
+ RewriteCond %{THE_REQUEST} ^.*/index.php
54
+
55
+ RewriteRule ^(.*)index.php$ http://www.hogehoge.com/$1 [R=301,L]
56
+
57
+ RewriteCond %{THE_REQUEST} ^.*/index.html
58
+
59
+ RewriteRule ^(.*)index.html$ http://www.hogehoge.com/$1 [R=301,L]
60
+
61
+
62
+
63
+ RewriteCond %{REQUEST_URI} ^/index.php/.*$
64
+
65
+ RewriteRule ^(.*)index.php$ http://www.hogehoge.com/ [R=301,L]
66
+
67
+
68
+
69
+ RewriteCond %{HTTP_HOST} ^hogehoge.com
70
+
71
+ RewriteRule (.*) http://www.hogehoge.com/$1 [R=301,L]
72
+
73
+
74
+
75
+ ErrorDocument 404 /404.html
76
+
77
+
78
+
79
+ RewriteCond %{REQUEST_URI} !^/contact/.*$
80
+
81
+ RewriteCond %{REQUEST_URI} !(.*css$)
82
+
83
+ RewriteCond %{REQUEST_URI} !(.*jpg$)
84
+
85
+ RewriteCond %{REQUEST_URI} !(.*png$)
86
+
87
+ RewriteCond %{REQUEST_URI} !(.*gif$)
88
+
89
+ RewriteCond %{REQUEST_URI} !(.*js$)
90
+
91
+ RewriteCond %{REQUEST_URI} !(.*ttf$)
92
+
93
+ RewriteCond %{REQUEST_URI} !(.*woff$)
94
+
95
+ RewriteCond %{REQUEST_URI} !(.*eot$)
96
+
97
+ RewriteCond %{REQUEST_URI} !(.*otf$)
98
+
99
+ RewriteCond %{HTTPS} on
100
+
101
+ RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R,L]
102
+
103
+
104
+
105
+ </IfModule>
106
+
107
+
108
+
109
+ # MIME Type 追加
110
+
111
+ <IfModule mime_module>
112
+
113
+ AddType text/cache-manifest .appcache
114
+
115
+ AddType image/x-icon .ico
116
+
117
+ AddType image/svg+xml .svg
118
+
119
+ AddType application/x-font-ttf .ttf
120
+
121
+ AddType application/x-font-woff .woff
122
+
123
+ AddType application/x-font-woff2 .woff2
124
+
125
+ AddType application/x-font-opentype .otf
126
+
127
+ AddType application/vnd.ms-fontobject .eot
128
+
129
+ </IfModule>
130
+
131
+
132
+
133
+ # ETags(Configure entity tags) を無視する設定
134
+
135
+ <ifModule mod_headers.c>
136
+
137
+ Header unset ETag
138
+
139
+ </ifModule>
140
+
141
+ FileETag None
142
+
143
+
144
+
145
+ # Enable Keep-Alive を設定
146
+
147
+ <IfModule mod_headers.c>
148
+
149
+ Header set Connection keep-alive
150
+
151
+ </IfModule>
152
+
153
+
154
+
155
+ #圧縮の設定
156
+
157
+ <ifModule mod_deflate.c>
158
+
159
+ <IfModule mod_filter.c>
160
+
161
+ # 古いブラウザでは無効
162
+
163
+ BrowserMatch ^Mozilla/4.0[678] no-gzip
164
+
165
+ BrowserMatch ^Mozilla/4 gzip-only-text/html
166
+
167
+ BrowserMatch \bMSIE\s(7|8) !no-gzip !gzip-only-text/html
168
+
169
+
170
+
171
+ # 画像など圧縮済みのコンテンツは再圧縮しない
172
+
173
+ SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png|ico|eot|woff|woff2)$ no-gzip dont-vary
174
+
175
+
176
+
177
+ AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
178
+
179
+ AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml
180
+
181
+ AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml
182
+
183
+ AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript application/json
184
+
185
+ AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp
186
+
187
+ AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf
188
+
189
+ AddOutputFilterByType DEFLATE font/truetype font/opentype
190
+
191
+ </IfModule>
192
+
193
+ </ifModule>
194
+
195
+
196
+
197
+ #ブラウザキャッシュの設定
198
+
199
+ <IfModule mod_headers.c>
200
+
201
+ <ifModule mod_expires.c>
202
+
203
+ ExpiresActive on
204
+
205
+ ExpiresDefault "access plus 1 days"
206
+
207
+
208
+
209
+ # CSS
210
+
211
+ ExpiresByType text/css "access plus 1 days"
212
+
213
+
214
+
215
+ # RSS
216
+
217
+ ExpiresByType application/atom+xml "access plus 1 hours"
218
+
219
+ ExpiresByType application/rdf+xml "access plus 1 hours"
220
+
221
+ ExpiresByType application/rss+xml "access plus 1 hours"
222
+
223
+
224
+
225
+ # データはキャッシュさせない
226
+
227
+ ExpiresByType application/json "access plus 0 seconds"
228
+
229
+ ExpiresByType application/ld+json "access plus 0 seconds"
230
+
231
+ ExpiresByType application/schema+json "access plus 0 seconds"
232
+
233
+ ExpiresByType application/vnd.geo+json "access plus 0 seconds"
234
+
235
+ ExpiresByType application/xml "access plus 0 seconds"
236
+
237
+ ExpiresByType text/xml "access plus 0 seconds"
238
+
239
+
240
+
241
+ # Favicon
242
+
243
+ ExpiresByType image/vnd.microsoft.icon "access plus 1 weeks"
244
+
245
+ ExpiresByType image/x-icon "access plus 1 weeks"
246
+
247
+
248
+
249
+ # HTML
250
+
251
+ ExpiresByType text/html "access plus 0 seconds"
252
+
253
+
254
+
255
+ # JavaScript
256
+
257
+ ExpiresByType application/javascript "access plus 1 weeks"
258
+
259
+ ExpiresByType application/x-javascript "access plus 1 weeks"
260
+
261
+ ExpiresByType text/javascript "access plus 1 weeks"
262
+
263
+
264
+
265
+ # マニフェスト
266
+
267
+ ExpiresByType application/manifest+json "access plus 1 weeks"
268
+
269
+ ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
270
+
271
+ ExpiresByType text/cache-manifest "access plus 0 seconds"
272
+
273
+
274
+
275
+ # 画像や動画
276
+
277
+ ExpiresByType audio/ogg "access plus 1 weeks"
278
+
279
+ ExpiresByType image/bmp "access plus 1 weeks"
280
+
281
+ ExpiresByType image/gif "access plus 1 weeks"
282
+
283
+ ExpiresByType image/jpeg "access plus 1 weeks"
284
+
285
+ ExpiresByType image/png "access plus 1 weeks"
286
+
287
+ ExpiresByType image/svg+xml "access plus 1 weeks"
288
+
289
+ ExpiresByType image/webp "access plus 1 weeks"
290
+
291
+ ExpiresByType video/mp4 "access plus 1 weeks"
292
+
293
+ ExpiresByType video/ogg "access plus 1 weeks"
294
+
295
+ ExpiresByType video/webm "access plus 1 weeks"
296
+
297
+
298
+
299
+ # Webフォント
300
+
301
+
302
+
303
+ # Embedded OpenType (EOT)
304
+
305
+ ExpiresByType application/vnd.ms-fontobject "access plus 1 months"
306
+
307
+ ExpiresByType font/eot "access plus 1 months"
308
+
309
+
310
+
311
+ # OpenType
312
+
313
+ ExpiresByType font/opentype "access plus 1 months"
314
+
315
+
316
+
317
+ # TrueType
318
+
319
+ ExpiresByType application/x-font-ttf "access plus 1 months"
320
+
321
+
322
+
323
+ # Web Open Font Format (WOFF) 1.0
324
+
325
+ ExpiresByType application/font-woff "access plus 1 months"
326
+
327
+ ExpiresByType application/x-font-woff "access plus 1 months"
328
+
329
+ ExpiresByType font/woff "access plus 1 months"
330
+
331
+
332
+
333
+ # Web Open Font Format (WOFF) 2.0
334
+
335
+ ExpiresByType application/font-woff2 "access plus 1 months"
336
+
337
+
338
+
339
+ # Other
340
+
341
+ ExpiresByType text/x-cross-domain-policy "access plus 1 weeks"
342
+
343
+ </IfModule>