我有一個非常簡單的網站來測試我的在線主機上的網址重寫,因爲我的原始應用程序在我的本地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]
現在當網址爲 「http://newcryo.com/」 它顯示主頁內容。
但是,當「http://newcryo.com/about/」或「http://newcryo.com/contact/」這說明不了什麼,它會打開about.php或contact.php不直接在index.php爲首頁
爲這兩種應該翻譯爲「http://newcryo.com/index.php?p=about 「但在這裏它呈現爲」 http://newcryo.com/about.php「
我的本地主機是WampServer與PHP 5.4.3 /阿帕奇2.2.22 我的遠程主機是OVH perso共享主機與PHP 5.4 /阿帕奇2.2.20
任何建議? 謝謝。
在這裏工作,但是當我刪除尾隨斜線它給予議案404未找到 – medk
你重寫規則應該是這樣的:'重寫規則^([^ /] + )/?$ /index.php?p=$1 [L,QSA]'因此可以選擇尾部斜線。 – anubhava