LoginSignup
2
1

More than 5 years have passed since last update.

【Wordpress】サーバ上のソース内の「http://」を「https://」に一括置換(複数ファイルの特定文字(URL)を一括置換)

Posted at

はじめに

  • WordpressのSSL化をする際に迷ったので備忘録的にまとめます。
    • WordpressをSSL化する際にDBデータやサーバ上のソース内を置換しないといけません。
    • Wordpressでよく使われているツールは大体DBが対象です。
    • サーバ上のファイル内を一括置換したい際はコマンドをうまく組み合わせる必要があります。

やること

  • サーバ上の複数ファイルの中にある特定の文字列(URL)をコマンドで一括置換します。

コマンド例

# find <一括置換したい対象ディレクトリ> -type f | xargs sed -i 's/<置換前の文字列>/<置換後の文字列>/g'

# find /var/www/html/ -type f | xargs sed -i 's/http:\/\/example.com\/dir1/https:\/\/example.com\/dir1/g'

注意点

  • URLが置換対象の場合、特殊文字と判断されないようにエスケープ文字を入れないといけません。
    • 「http://」は「http:\/\/」にしましょう。
2
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
2
1