我想重新排列我的网站,并将所有客户页面移动到目录(/ 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