作为查询字符串中的变量传递的部分 url 错误地包含其查询字符串

发布于 2024-09-26 06:29:08 字数 1722 浏览 2 评论 0原文

我正在将站点移动到另一台服务器,但遇到了问题。

该网站使用 .htaccess 重定向到 index.php,因此 index.php 可以使用 $_SERVER['REQUEST_URI'] 加载正在调用的任何页面...但是我找不到旧服务器具有 .htaccess 规则的位置。 ..所以我正在做我自己的。

我使用的 .htacess 规则是:

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php/?$1 [L,QSA]

URL 是 newsiteurl.com/racintv/video_view?channel_id=2

并通过打印出我得到的 index.php 页面上的参数

数组 ( [page] => racintv/video_view?channel_id=2 )

它应该加载 video_view 页面并传递 channel_id (加载视频播放列表)。情况并非如此,因为它认为要加载的页面实际上是 /video_view?channel_id=2

在旧站点上,我在它打印的 index.php 页面上打印出参数

数组 ( [page] => racintv/video_view )

并在视频正确加载时正确传递 ?channel_id=2

我的 .httacess 中缺少什么可以正确传递 ?channel_id=2 ?

这是解析 URI 的 PHP 代码

$path_info = trim(substr($_SERVER['REQUEST_URI'],1)) ;
$var_array = explode('/',$path_info);
$num_vars = sizeof($var_array);
if ($num_vars==1 or !($var_array[1])) {// in the form of '/foo' or '/foo/'
  if ($var_array[0] && ! strstr($var_array[0],'index')) {
    $var_array[1] = 'index'; // use index as the default page
    $num_vars = 2;
  }
}
if ($num_vars >= 2) { // in the form of '/foo1/foo2[/foo3 ...]'
  $tmp_array = explode('.',$var_array[1]);
  $var_array[1] = $tmp_array[0];
  $page = $var_array[0] .'/'.$var_array[1];
  $vars['page'] = $page;
  $q_str = '';
  for ($i=2;$i<$num_vars;$i++) {
    $key = $var_array[$i];
    $value = $var_array[++$i];
    if ($key && $value) {
      $vars[$key] = $value;
      $q_str .= "$key=$value&";
      $$key=$value;
    }
  }
}

//结束搜索引擎友好的 url 解析

I am in the process of moving a site to another server and I've ran into a problem.

The site uses .htaccess to redirect to index.php so the index.php can use $_SERVER['REQUEST_URI'] to load the whatever page is being called... However i cannot find where the old server has the .htaccess rules...so I am doing my own.

The .htacess rules I use are:

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php/?$1 [L,QSA]

the URL is newsiteurl.com/racintv/video_view?channel_id=2

and by printing out the params on the index.php page I am getting

Array ( [page] => racintv/video_view?channel_id=2 )

It should load the video_view page and pass channel_id (which loads a video playlist). This is not the case as it thinks the page to load is actually /video_view?channel_id=2

On the old site, I print out the params on the index.php page it prints

Array ( [page] => racintv/video_view )

and passes the ?channel_id=2 correctly as the video loads correctly

What am I missing in my .httacess that would pass ?channel_id=2 correctly?

Here is the PHP code which parses the URI

$path_info = trim(substr($_SERVER['REQUEST_URI'],1)) ;
$var_array = explode('/',$path_info);
$num_vars = sizeof($var_array);
if ($num_vars==1 or !($var_array[1])) {// in the form of '/foo' or '/foo/'
  if ($var_array[0] && ! strstr($var_array[0],'index')) {
    $var_array[1] = 'index'; // use index as the default page
    $num_vars = 2;
  }
}
if ($num_vars >= 2) { // in the form of '/foo1/foo2[/foo3 ...]'
  $tmp_array = explode('.',$var_array[1]);
  $var_array[1] = $tmp_array[0];
  $page = $var_array[0] .'/'.$var_array[1];
  $vars['page'] = $page;
  $q_str = '';
  for ($i=2;$i<$num_vars;$i++) {
    $key = $var_array[$i];
    $value = $var_array[++$i];
    if ($key && $value) {
      $vars[$key] = $value;
      $q_str .= "$key=$value&";
      $key=$value;
    }
  }
}

//end of search engine friendly url parsing

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

溺ぐ爱和你が 2024-10-03 06:29:08

缺少页面参数:

RewriteRule ^(.+)$ /index.php/?page=$1 [L,QSA]

The page parameter is missing:

RewriteRule ^(.+)$ /index.php/?page=$1 [L,QSA]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文