request_uri 和 array 之类的东西

发布于 2024-11-19 13:31:50 字数 931 浏览 0 评论 0原文

我有一个代码需要帮助。

    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=$VARIABLEhttp://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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卸妝后依然美 2024-11-26 13:31:50

您不必在 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';

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:

RewriteRule ^(.*?)/(.*?)$ index.php?page=$1&sub=$2 [L]
RewriteRule ^(.*?)$ index.php?page=$1 [L]

The above will mask redirect http://link.com/testmore/index to http://link.com/index.php?page=testmore&sub=index. It will also redirect http://link.com/variable to http://link.com/index.php?page=variable.

$uriArray = explode('/', $_SERVER['REQUEST_URI']);
if (in_array($uriArray[1], $pageArray)){
     dostuff($uriArray[1]);
else
     echo '404';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文