我想重新排列我的網站,並將所有客戶頁面移動到目錄(/ customerPages)中,同時保持相同的URL(訪問該頁面的URL和顯示的URL在瀏覽器中)。我正在使用Apache
和PHP
(CakePHP
)。在Apache中移動頁面,同時跳轉相同的URL
我試着重新佈線我404錯誤頁面以下列方式:
// Redirect customers to customers landing pages under /customerPages
if (strpos($message,'customerPages') == false) {
$url = 'http://'.$_SERVER['HTTP_HOST'].'/customerPages'.$message;
$homepage = file_get_contents($url);
echo $homepage;
}
但是這種解決方案打破了使用相對路徑編寫的所有圖像。
後來我嘗試使用重定向來代替:
if (strpos($message,'customerPages') == false) {
$url = 'http://'.$_SERVER['HTTP_HOST'].'/customerPages'.$message;
header("Location: ".$url);
}
但比URL變化。我試圖用RewriteRule
擺弄,但沒有運氣。
如何使用第一,第二或任何其他方法實現此目的?
file_exists由於是URL而不起作用,所以'site .com/ABB'實際上是'site.com/ABB/index.php'或'site.com/ABB/index.html'。同樣,我不明白它將如何編輯客戶端瀏覽器中的URL? – Kuf
'if(file_exists('/ newpath /'.$ filename)&&(!is_dir('/ newpath /'.$ filename))){...}' – clover
k,我可以爲URL重寫做什麼? – Kuf