我有以下情况:
Codeigniter网站(我们称之为WebA)安装在 sebserver “/” 的根目录下,可从域访问:www.example.com。
另一个 Codeigniter 网站(我们称之为WebB)安装在同一网络服务器中的子文件夹“/subfolder”中,可从域访问:www.example2.com。
我有 2 个删除 index.php 的 .htacces 文件,安装在 WebA 和 WebB 上:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (auth|register|secure)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(static|auth|register|secure)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
AddType application/vnd.ms-fontobject .eot
AddType application/octet-stream .otf .ttf
我在 /application/config/config.php 中的 WebA 上进行了配置:
$config['base_url'] = 'http://example.com/';
在 /subfolder/application/config/config.php 中的 WebB 中:
$config['base_url'] = 'http://example2.com/';
错误一:
使用此配置,当我访问 www.example2.com 时,我得到:
404页面不存在
错误2:
如果我将 WebB 的 .htaccess RewriteBase 行更改为:
RewriteBase /subfolder/
我在索引“http://example2.com/”中输出了 html,但它不会加载我的任何 JS 或 CSS,因为它不是加载脚本而是加载它:
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Trying to get property of non-object</p>
<p>Filename: controllers/html.php</p>
<p>Line Number: 60</p>
</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message: Cannot modify header information - headers already sent by (output started at /var/www/subfolder/system/core/Exceptions.php:185)</p>
<p>Filename: helpers/url_helper.php</p>
<p>Line Number: 546</p>
</div>
它在尝试导航页面时也会输出此错误,但我没有得到 Html。
第一个错误似乎是由于配置错误,我的数据库模型无法正常工作。
错误 3:
如果我将 WebB 的 config.php 更改为:
$config['base_url'] = 'http://example.com/subfolder/';
.htaccess 中的 WebB 的 RewriteBase 行:
RewriteBase /subfolder/
当通过 www.example.com/subfolder/ 和 www.example2.com 访问时,它工作正常,但问题是 WebB 的链接,我需要它们作为 www.example2.com 而不是 www.example.com/子文件夹/
WebA 一直在工作。
我在多个网站上使用相同的代码没有任何问题,但我以前从未遇到过这种情况。有任何想法吗?