LoginSignup
0
0

More than 3 years have passed since last update.

「移転しました」ページの作り方【Webサーバーの移転】

Last updated at Posted at 2019-08-05

404 Not Foundの代わりに、自作のページ、「移転しました」を表示させる

概要

  1. まずVisual Studio CodeなどでHTML文書を作成します。その文書には「移転しました。移転先はこちら」などと記述する。
  2. ウェブサーバーからほぼすべてのHTMLなどのコンテンツを削除する。
  3. アップロードする。
  4. Apacheのhttpd.confの設定をいじくる。

具体的に申しますと・・・

VisualStudioCodeでHTML文書を作成する。

2019-08-04 145151 404NotFoundページ作成.png

ちなみにウェブブラウザで表示させるとこうなる。
2019-08-04 145151 404NotFoundページ作成2.png

削除する

ほぼすべてのhtmlファイルを削除する。
index.htmも消しちゃいましょう。
sudo rm /var/www/html/*

アップロードする

今回はTeraTerm経由でアップロードします。
2019-08-05 404NotFound13.png

SCP 送信先に /var/www/html/ と書き込んで、
2019-08-05 404NotFound14.png
Enterを押してください。

試しに保存先を表示してみた。
2019-08-05 404NotFound16.png
404NotFound.htm以外のhtmlファイルも削除してあります。

httpd.confをいじくる。

sudo nano /etc/httpd/conf/httpd.confと入力する。
2019-08-05 404NotFound6.png
すると↑のように表示されると思う。

この設定ファイルのうち、

#ErrorDocument 404ではじまる行に注目する。
#を外してください。それから、
ErrorDocument 404 /404NotFound.htmと入力する。
2019-08-05 404NotFound21.png

Ctrl + x を入力し、
2019-08-05 404NotFound8.png
Enterを押して

2019-08-05 404NotFound9.png
もう1回Enterを押して下さい。

service httpd restartと入力します。
2019-08-05 404NotFound18.png

パスワードを入力して下さい。
2019-08-05 404NotFound20.png

すると、ブラウザで適当にhtmlファイルへのURLを入力しても、
「移転しました。」と表示されるのです。
2019-08-05 404NotFound17.png

おしまい。

余談ですが・・・

試していませんが、おそらく403 Forbiddenのページも何らかの「移転しました」っていう移転通知のHTMLファイルに差し替えれば何らかのcgiにアクセスした場合もちゃんと案内できるんじゃないでしょうか。

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