Php URL重写不适用于共享主机

Php URL重写不适用于共享主机,php,apache,mod-rewrite,url-rewriting,Php,Apache,Mod Rewrite,Url Rewriting,我有一个非常简单的网站,可以在我的在线主机上测试url重写,因为我的原始应用程序在本地WampServer上运行良好,但在我的在线主机上无法运行 这是我的密码: index.php: <?php $p = $_GET['p']; $pages = array ( 'home' => 'home.php', 'about' => 'about.php', 'contact' =&g

我有一个非常简单的网站,可以在我的在线主机上测试url重写,因为我的原始应用程序在本地WampServer上运行良好,但在我的在线主机上无法运行

这是我的密码:

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>
现在,当url为“”时,它将显示主页内容

但当“”或“”时,它将不显示任何内容,并直接打开about.php或contact.php,而不是像主页那样在index.php中打开

对于这两种情况,它都应转换为“”,但在这里它呈现为“”

我的本地主机是带有PHP5.4.3/Apache2.2.22的WampServer 我的远程主机是一个带有PHP5.4/Apache2.2.20的OVH perso共享主机

有什么建议吗?
谢谢。

多视图在这里可能是个问题

将选项更改为:

Options +FollowSymLinks -MultiViews

在这里它可以工作,但当我删除尾随斜杠时,它会给出一个404 not found。您的重写规则应该是这样的:
RewriteRule^([^/]+)/?$/index.php?p=$1[L,QSA]
,因此尾随斜杠是可选的。
<?php

    $body = '

        <h1>About</h1>

        This is the about page

    ';

?>
<?php

    $body = '

        <h1>Contact</h1>

        This is the contact page

    ';

?>
Options +FollowSymLinks

RewriteEngine On



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

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