LoginSignup
3
8

More than 5 years have passed since last update.

PHPファイルを拡張子.htmlで動かす

Posted at

WordPressをサイトルートとは別のディレクトリにインストールしていて、
WordPress配下でないトップページを一部動的化したい、
index.phpは既に使ってて使えない、とかそんなときに利用した方法です。

.htaccessファイルに以下のとおり記載することで、
PHPファイルを拡張子.htmlで動作・表示させることができます。
記述は先頭の行でよいです。
AddHandler fcgid-script .html

XサーバーだとこれでOKでした。
ただしレンタルサーバーの仕様によって記述内容を変える必要があるようです。


ロリポップ
AddHandler php○-script .htm .html

※○の箇所にPHPのバージョンを記入。
例)PHPのバージョンが5.3なら:
AddHandler php5.3-script .htm .html


ヘテムル
AddHandler php○-script .html

※○の箇所にPHPのバージョンを記入。
例)PHPのバージョンが5.3なら:
AddHandler php5.3-script .html


さくらインターネット
Action myphp-script /php.cgi
AddHandler myphp-script .php .html

さくらの場合これだけではダメで、
php.cgiというファイルを作成して、以下を記述します。

#!/bin/sh
exec /usr/local/bin/php-cgi

ファイルのアップ先は.htaccessと同階層。

3
8
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
3
8