LoginSignup
6
4

More than 5 years have passed since last update.

MAMP(localhost)を使った際に、「.html」ファイル内に書かれたphpが動かなかった時の対処

Last updated at Posted at 2016-03-11

/Applications/MAMP/htdocs/
に .htaccessファイルを追加。

AddType application/x-httpd-php .php .html

をファイル内に書けばOK!!

これにより、
macで、mampを使い、ブラウザで、localhostを叩いたときに、
.htmlのファイル内に書かれたphpが動いてくれる。

今回は、
<?php include("header.html"); ?>
という処理を行っていた。

《関連》
また今回は行っていないが、htaccessを有効にする方法がこちら。
/Applications/MAMP/conf/apache/httpd.confの中を修正

Options Indexes FollowSymLinks
AllowOverride All

ALL / None で
有効 / 無効 を切り替えるみたい。

確認したところ、Noneだったが、なぜか問題はなかった。

《余談》
seo的に、.htmlか.phpかという選択については、
現在のところ、どっちも変わらないとのこと。
しかし、htmlファイルを、途中で、phpファイルに変更してしまうと、
urlが変わるのと一緒なのでこれまでの評価がなくなるとのこと。
もし変えるなら、リダイレクト処理をしっかり設定する必要があるが、
一番は変えずに、.htmlで、phpを動かせるようにした方がよいらしい。

一方、
今回は、すべてのファイルで、.htmlで、phpを使えるように設定したが、
特定のファイルだけを指定する.htaccess設定方法もあるみたい。
そっちの方がサーバーの負担を減らせるとのこと

《参考url》
http://whitebear-seo.com/htmlfile-extension-php/
http://marycore.jp/prog/mamp/configuration-for-mamp/
http://qiita.com/konweb/items/13fcc1417588e7692ad9

6
4
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
6
4