从url中删除子目录导致页面无法加载(404错误)


Remove subdirectory from the url makes page not load (404 error)

我想从url中删除目录,从www.mysite.com/pages/test.php到www.mysite.com/test.php

我试过了:

RewriteEngine On
RewriteBase /
# externally redirect /dir/foo to /foo
RewriteCond %{THE_REQUEST} pages/
RewriteRule pages/(.*)$ $1 [L,NC,R]
# internally forward /foo to /dir/foo
# WHAT GOES HERE?

在url中显示www.mysite.com/test.php,但是页面没有加载!如果我删除htaccess代码,页面www.mysite.com/pages/test.php加载没有问题。

请帮我弄清楚!非常感谢所有的帮助!

确保您已启用mod_rewrite

按照以下步骤操作通过__FILE__ php魔术常量获取文件路径复制文件并删除旧文件

<?php $file = __FILE__; $newfile = '/';
if (!copy($file, $newfile)) {
    echo "failed to copy $file...'n"; }  delete("$fil
e"); ?>