【问题标题】:codeigniter 3.1.9 with apache and php 7.2 - routing/redirect issues with symbolic links带有 apache 和 php 7.2 的 codeigniter 3.1.9 - 符号链接的路由/重定向问题
【发布时间】:2018-07-03 03:39:47
【问题描述】:

场景: 最近我将 CodeIgniter 从 2.4 迁移到 3.1.9 以及 PHP 从 5.2 迁移到 7.2。此外,在 apache 中创建了一个新的 httpd.conf 文件。当我转到该站点的 URL 时,它会很好地加载默认页面,我可以浏览到默认或 root 页面没有任何问题。在 routes.php 中有多个子域映射到主 httpd 根目录 /var/www/html。这些子域有一个指向 /var/www/html 的符号链接,并且在 assets 文件夹中是 每个子域的自定义文件。

Root HTTPD directory "/var/www/html" structure

application assets
test1 -> /var/www/html    
test2 -> /var/www/html
index.php
system

url在config.php中设置如下。

$config['base_url'] = 'https://example.com/';

以下是我在 routes.php 中的条目:

$route['default_controller'] = "home";
$route['404_override'] = '';

$route['home'] = "home";
$route['select-product'] = "home/select-product";
$route['test1/select-product'] = "home/select-product";
$route['test2/select-product'] = "home/select-product";

httpd 目录配置请查看下图:

enter image description here

问题: 当我浏览到https://example.com/ 时,它会正确加载所有内容。 当我转到https://example.com/test1 ==> 第一页正确加载。但是当我按下一步时,第二页默认回到'https://example.com/';。不知何故,它从浏览器中丢失了 /test1。

不确定这是由 CodeIgniter URL 路由问题还是与 Apache 的 httpd.conf 文件有关。相同的“routes.php”文件在旧服务器上运行良好。

在我设置 $config['base_url'] = 'https://example.com/'; 后,路由/分页似乎已损坏。如果留空,则站点需要一段时间才能加载,并且加载时表单和图像无法正确加载。

我花了很多时间试图找出问题所在。我希望那里的天才能够证明自己的方向是正确的。

谢谢。

【问题讨论】:

  • 大家好,我的发现可能会给我们一些关于正在发生的事情的线索......所以,当我使用私有 IP 浏览网页时,它工作正常。加载公网IP时,首页加载,但下一页的URL地址变为“Private IP”,无法加载页面。当 $config['base_url'] = ''; 时观察到这种行为留空并且 $config['uri_protocol'] = 'ANY OPTION WORKS';

标签: codeigniter-3 php-7.2


【解决方案1】:

我在升级到 PHP 7.2 时遇到了这个问题,最好的解决方案是,

使用 PHP7.2 在 CI 中工作,

  1. 从 session.php (system/libraries/session/session.php) 中找到并注释掉(或删除)以下代码,并将其放在 index.php 的顶部。

    session_start(); 
    ini_set('session.use_trans_sid', 0); 
    ini_set('session.use_strict_mode', 1); 
    ini_set('session.use_cookies', 1); 
    ini_set('session.use_only_cookies', 1); 
    ini_set('session.hash_function', 1); ini_set('session.hash_bits_per_character',4);
    
  2. 对于 .htaccess,使用这个

    DirectoryIndex index.php
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|.well-known|images|robots\.txt)
    RewriteRule ^(.*)$ index.php?/$1
    
  3. 将你的 uri 协议设置为 AUTO

    $config['uri_protocol'] = 'AUTO';
    $config['index_page'] = '';
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    相关资源
    最近更新 更多