request_uri 和 array 之类的东西
我有一个代码需要帮助。
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
I已完成所有 .htaccess
并正常工作,这不会成为问题。 问题是,当我输入 http://link.com/testmore/index
时,它不会显示指定的页面,而是显示 404 页面。
I have a code which I need help on.
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'; }
This uses URI requests and it makes it from http://link.com/index.php?page=$VARIABLE
to http://link.com/variable
I have all the .htaccess
done and working which wont be a problem.
The problem is that when I type http://link.com/testmore/index
it wont show that specified page, but instead a 404 page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必在 PHP 页面中执行任何工作。您的页面无法正常工作的原因是您的 .htaccess 代码不正确。试试这个:
上面的代码会将
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
。You should not have to do any work in the PHP page. The reason your pages aren't working is because your .htaccess code is incorrect. Try this:
The above will mask redirect
http://link.com/testmore/index
tohttp://link.com/index.php?page=testmore&sub=index
. It will also redirecthttp://link.com/variable
tohttp://link.com/index.php?page=variable
.