PHP在URL中使用不同参数重定向同一页面


PHP redirect on same page with different parameters in URL

我有一个页面,ID和slug应该从URL更改。我正在使用codeigniter并从数据库中获取随机记录

public function view_post()
 {
      $query = $this->db->query('SELECT * FROM `tbl_links` ORDER BY RAND() LIMIT 0,1');
      $src = $query->row();
      $URL = $src->URL;
      $ID = $src->ID;        
      $tmpurl = parse_url($URL);

      $scheme = $tmpurl['scheme'];
      $host = $tmpurl['host'];
      if(!empty($tmpurl['path']))
      {
           $path = $tmpurl['path'];
           $finalURL = $host . $path;
      }
      else
      {
           $finalURL = $host;
      }
      redirect(base_url() . 'index.php/post/view_post/'.$ID.'/'.$finalURL.'');
 }

我想用不同的ID在同一页面上重定向这是一个错误页面重定向不正确

我需要在<iframe> 中显示URL

所需URL

http://localhost:81/link/index.php/post/view_post/1/url comes here

检查重定向url是否正确。我认为这可能是错误的,因为你正在连接$finalURL,其中包含$hostname和last。只需评论此重定向行并打印url。请尝试检查输出的url是否正确。

如果url是正确的,并且在post-controller中一切都很好,那么可能会出现htaccess问题
https://ellislab.com/forums/viewthread/151471/#870328

这应该是

public function view_post($action = NULL)
 {
   if(isset($action)){
      include "http://" . substr($action, strrpos( $action , '/' ));
   } else {
      $query = $this->db->query('SELECT * FROM `tbl_links` ORDER BY RAND() LIMIT 0,1');
      $src = $query->row();
      $URL = $src->URL;
      $ID = $src->ID;        
      $tmpurl = parse_url($URL);

      $scheme = $tmpurl['scheme'];
      $host = $tmpurl['host'];
      if(!empty($tmpurl['path']))
      {
           $path = $tmpurl['path'];
           $finalURL = $host . $path;
      }
      else
      {
           $finalURL = $host;
      }
      redirect(base_url() . 'index.php/post/view_post/'.$ID.'/'.$finalURL.'');
    }
 }