サポート » 使い方全般 » さくらサーバーのHTMLでPHPを動かすための.htaccess

  • 解決済 makin234

    (@makin234)


    HTMLサイトにワードプレスの新着記事を載せたいと思い。

    こちらのサイト(http://planbworks.net/web/html-and-wordpress.html)などを参考にやっていますが、.htaccessをアップロードすると

    「ページは機能していません、サイトURLでは現在このリクエストを処理できません。」と表示されてしまいます。

    行った手順
    1、以下を記述したphp.cgiをindex.htmlのある階層にアップロード。属性を705に変更(755と書いてるブログもあったので両方試しました。

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

    2、.htaccessに以下を追加し、index.htmlのある階層にアップロード

    Action myphp-script /php.cgi
    AddHandler myphp-script .php .html

    .htaccessを最初の状態に戻すと正常に表示されるのでそこではないかと思います。

    ちなみに.htaccessはこのようにしてあります。

    <ifModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault “access plus 30 minutes”
    ExpiresByType text/html “access plus 10 seconds”
    ExpiresByType image/jpg “access plus 7 days”
    ExpiresByType image/jpeg “access plus 7 days”
    ExpiresByType image/gif “access plus 7 days”
    ExpiresByType image/png “access plus 7 days”
    ExpiresByType image/bmp “access plus 7 days”
    ExpiresByType text/css “access plus 1 month”
    ExpiresByType text/js “access plus 1 month”
    ExpiresByType application/pdf “access plus 1 month”
    ExpiresByType text/x-javascript “access plus 1 month”
    ExpiresByType application/javascript “access plus 1 month”
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    ExpiresByType application/x-javascript “access plus 1 month”
    ExpiresByType application/x-shockwave-flash “access plus 1 month”
    ExpiresByType image/x-icon “access plus 1 month”
    </ifModule>
    RewriteEngine Off
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(ドメイン\.biz)(:80)? [NC]
    RewriteRule ^(.*)$ サイトURL/$1 [R=301,L]
    Action myphp-script /php.cgi←追加
    AddHandler myphp-script .php .html←追加

    よろしくお願いします。

10件の返信を表示中 - 1 - 10件目 (全10件中)
  • それは、WordPressを設置したのと同じ階層に index.html を設置して .htaccess の設定に上記を追加したのでしょうか。

    WordPressとは全く別のディレクトリで、index.html 内の PHPが動作するかどうか、サンプル的にテストしてみてはと思います。

    トピック投稿者 makin234

    (@makin234)

    ありがとうございます。最初に行ったのは

    ●index.html←新着を表示させたい
    ●page01.html
    ●CSS
    ●img
    ●blog←ワードプレス
    ●.htaccess
    ●php.cgi

    という形です。

    試しにtestというフォルダをつくり適当なindexhtmlとhtaccessとphp.cgiを入れてみましたが、「ページは機能していませんHTTP ERROR 500」となってしまいます。

    アップロードもアスキーモードでしました。

    ●test
    ⇒index.html
    ⇒.htaccess
    ⇒php.cgi

    htaccessに

    Action myphp-script /php.cgi
    AddHandler myphp-script .php .html

    のみ記述。文字コード EUCJP 改行コード LF 属性604

    CGIに

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

    を記述。文字コード EUCJP 改行コード LF 属性705

    どこかおかしな点はあるのでしょうか?

    CentOS ですか?
    また、ルートがおかしくないですか

    まず test フォルダ内のテストコードが動作することを目指しましょう。

    URL:http://◯◯/test/index.html

    フォルダ構成
    ◯◯/test
    ┣ index.html
     ┣ .htaccess
    ┗ php.cgi

    とします。

    .htaccess
    Action myphp-script /test/php.cgi
    AddHandler myphp-script .php .html
    
    index.html
    <?php
    echo "test";
    ?>


    http://◯◯/test/index.html
    にアクセスして「test」が表示されるかどうかですね。

    トピック投稿者 makin234

    (@makin234)

    kimipoohさん。ありがとうございます。

    とりあえず、http://◯◯/test/index.html
    の方では「test」と表示されました。

    http://◯◯/test/index.html
    ではphpが動かせるのは確認できました。

    ということはどういう事なんでしょうか?

    まずはそれで、PHPプログラムを index.html という 拡張子 HTMLで実行できたということになります。

    となれば次は
    ●index.html←新着を表示させたい
    ●page01.html
    ●CSS
    ●img
    ●blog←ワードプレス
    ●.htaccess
    ●php.cgi

    .htaccess の末尾に
    Action myphp-script /php.cgi
    AddHandler myphp-script .html
    を追加。
    
    index.html
    <?php
    echo "test";
    ?>

    にて、 http://◯◯/index.html
    で testが表示されるか確認しましょう。

    ここで、AddHandler myphp-script .html のみにしてます。 .phpは特に今回使わないので指定しなくていいはず。.phpは WordPressだけであり、その設定は blog/.htaccess に記載されているはず。

    あと .htaccessの中身で気になった

    RewriteEngine Off
    RewriteEngine On

    は2つあっても意味が無いので
    RewriteEngine On
    だけにして、

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(ドメイン\.biz)(:80)? [NC]
    RewriteRule ^(.*)$ サイトURL/$1 [R=301,L]
    
    Action myphp-script /php.cgi←追加
    AddHandler myphp-script .php .html←追加

    のように念のため、RewriteRuleとActionの間に1つ空行をいれておきます。

    これで問題なければ、あとの問題は index.html 内にかいたPHPコードがおかしいということになります。

    トピック投稿者 makin234

    (@makin234)

    kimipoohさん

    何度も本当にありがとうございます。

    .htaccessのRewriteEngine Offを削除し

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(ドメイン\.biz)(:80)? [NC]
    RewriteRule ^(.*)$ サイトURL/$1 [R=301,L]
    ←空行
    Action myphp-script /php.cgi
    AddHandler myphp-script .html

    として改行コードLF 属性604

    .cgiは属性705として試したのですが、やはりどうしても.htaccessに

    Action myphp-script /php.cgi
    AddHandler myphp-script .html

    を加えるとリクエストを処理できませんと出てしまいます。

    試しに.htaccessの中身を

    Action myphp-script /php.cgi
    AddHandler myphp-script .html

    のみにしてみたのですがそれでもだめでした。

    こうなると後は何が邪魔しているのかわかりますでしょうか?
    index.htmlにていくつかjavascriptを使っていますがそちらの関係はあるのでしょうか?

    その index.html がどのように記載されているか分からないので判断つかず。
    たとえば、test フォルダに入れた index.html を トップの aaa.html にコピーして

    http://◯◯/aaa.html では test と表示されますか。

    これが表示されているなら、 index.html の中が何かおかしいということになります。

    さくらサーバーで PHPエラー出力されるよう設定して何が原因かログをチェックしてみてはと思います。エラーログの出し方は
    参考:http://nuuno.net/note/wordpress-internal-server-error-sakura/ 
    をすればいいかなと思います。

    トピック投稿者 makin234

    (@makin234)

    kimipoohさん

    いろいろありがとうございました。なんとか解決できそうです。

    どうやらhtmlにある

    <?xml version=”1.0″ encoding=”Shift_JIS”?>

    がいけなかったみたいです。
    これを

    <?php echo ‘<?xml version=”1.0″ encoding=”Shift_JIS”?>’; ?>

    と書き換えたらうまく動きました!

    何度も何度もほんとうにありがとうございました。

    トピック投稿者 makin234

    (@makin234)

    ありがとうございました。

10件の返信を表示中 - 1 - 10件目 (全10件中)
  • トピック「さくらサーバーのHTMLでPHPを動かすための.htaccess」には新たに返信することはできません。