2与主文件夹在同一服务器上的Codeigniter安装

时间:2013-01-17 18:11:06

标签: php .htaccess codeigniter

我有以下情况:

Codeigniter网站(让我们称之为 WebA )安装在sebserver“/”的根目录下,可从域名访问:www.example.com。

另一个Codeigniter网站(让我们称之为 WebB )安装在子文件夹“/子文件夹”中的同一个网络服务器中,可从域名访问:www.example2.com。

我有2个.htacces文件删除了安装在WebA和WebB中的index.php:

<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/';

在/Bubfolder/application/config/config.php中的WebB中:

$config['base_url'] = 'http://example2.com/';

错误1:

使用此配置,当我访问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/';

WebB的RewriteBase在.htaccess中排到:

RewriteBase /subfolder/

它的工作正常,当访问www.example.com/subfolder/和www.example2.com时,问题是WebB的链接,我需要它们作为www.example2.com而不是www.example的.com /子文件夹/

WebA始终在工作。

我有相同的代码在多个网站上工作没有任何问题,但我以前从未遇到过这种情况。有什么想法吗?

2 个答案:

答案 0 :(得分:0)

在您的安装中使用虚拟主机可以免除配置.htaccess的痛苦。

答案 1 :(得分:0)

好的,所以我终于做到了这一点,我做了什么:

我要求系统管理员将所有网站更改为使用虚拟主机Hicham LEMGHARI sugested,但我不知道他是否做得对,因为我仍然在WebB上有错误:

WebA安装在/ var / www / subfolderA

WebB安装在/ var / www / subfolderB

WEBA

WebA的htaccess文件将RewriteBase行配置为:

RewriteBase /subfolderA/

和config.php:

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

韦伯

WebB的htacces文件完全改为这4行:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 

并且config.php为:

$config['base_url'] = 'http://example2.com/';