2

元のアプリケーションはローカルの WampServer では正常に動作しましたが、オンライン ホストでは動作しなかったため、オンライン ホストで URL 書き換えをテストするための非常に単純なサイトがあります。

ここに私のコードがあります:

index.php:

    <?php

    $p = $_GET['p'];

    $pages = array (

        'home'      => 'home.php',
        'about'     => 'about.php',
        'contact'   => 'contact.php'

    );

    if (isset($pages[$p]))  $page = $pages[$p];

    else                            $page = 'home.php';

    include $page;

?>



<!doctype html>

<html>

    <head></head>

    <body>

        <?php echo $body; ?>

        <br /><br /><br />

        <a href="http://newcryo.com/">HOME</a> - <a href="http://newcryo.com/about/">ABOUT</a> - <a href="http://newcryo.com/contact/">CONTACT</a>

    </body>

</html>

home.php:

<?php

    $body = '

        <h1>Home</h1>

        This is the home page

    ';

?>

about.php:

<?php

    $body = '

        <h1>About</h1>

        This is the about page

    ';

?>

contact.php:

<?php

    $body = '

        <h1>Contact</h1>

        This is the contact page

    ';

?>

.htaccess:

Options +FollowSymLinks

RewriteEngine On



# home
RewriteRule ^$ index.php?p=home [L]

# other pages
RewriteRule ^([^/\.]+)/$ index.php?p=$1 [L]

URL が「http://newcryo.com/」の場合、ホームページのコンテンツが表示されます。

しかし、「http://newcryo.com/about/」または「http://newcryo.com/contact/」の場合、何も表示されず、ホームのようにindex.php内ではなく、about.phpまたはcontact.phpを直接開きますページ

どちらも「 http://newcryo.com/index.php?p=about 」に変換する必要がありますが、ここでは「 http://newcryo.com/about.php」としてレンダリングします

私のローカル ホストは、PHP 5.4.3 / Apache 2.2.22 を使用する WampServer です。私のリモート ホストは、PHP 5.4 / Apache 2.2.20 を使用する OVH 個人共有ホストです。

なにか提案を?ありがとう。

4

1 に答える 1