我有一个我需要帮助的代码。
if ($_SERVER['REQUEST_URI'] == '/testmore/' || $_SERVER['REQUEST_URI'] == '/testmore/home') { $_SERVER['REQUEST_URI'] = '/testmore/index'; }
echo $_SERVER['REQUEST_URI']; echo '<br>';
$page = $_SERVER['REQUEST_URI'];
function dostuff($pagesC) { echo 'yes!<br>'; echo $pagesC.'<br>'; }
$pageArray = Array('index', 'login');
$directory = '/testmore/'; // Directory if in one. Otherwise, leave it as '/'.
$uriArray = explode('/', strstr($_SERVER['REQUEST_URI'], $directory));
if (in_array($uriArray[0], $pageArray)) {
dostuff($uriArray[0]); } else {
echo '404'; }
这使用了URI请求,它从http://link.com/index.php?page=$VARIABLE
到http://link.com/variable
我完成所有.htaccess
并且正在工作,这不会成为问题。
问题是,当我输入http://link.com/testmore/index
时,它不会显示指定的页面,而是显示404页面。
答案 0 :(得分:2)
您不应该在PHP页面中做任何工作。您的网页无法正常工作的原因是您的.htaccess代码不正确。试试这个:
RewriteRule ^(.*?)/(.*?)$ index.php?page=$1&sub=$2 [L]
RewriteRule ^(.*?)$ index.php?page=$1 [L]
以上内容将屏蔽重定向http://link.com/testmore/index
至http://link.com/index.php?page=testmore&sub=index
。它还会将http://link.com/variable
重定向到http://link.com/index.php?page=variable
。
$uriArray = explode('/', $_SERVER['REQUEST_URI']);
if (in_array($uriArray[1], $pageArray)){
dostuff($uriArray[1]);
else
echo '404';