简体   繁体   English

如果在/根文件夹中还安装了CodeIgniter,则子目录中的CodeIgniter会给出404错误

[英]CodeIgniter in Sub-directory gives 404 error, when CodeIgniter is installed in / root folder also

I have a site created using CodeIgniter, and the application is installed on the web root (/). 我有一个使用CodeIgniter创建的网站,该应用程序安装在Web根目录(/)上。 This is a shared hosting environment on GoDaddy. 这是GoDaddy上的共享托管环境。 For creating a Development environment, I copied the same and created a /development folder in the / root. 为了创建开发环境,我将其复制并在/根目录中创建了/ development文件夹。

Now, my main site works well, but when I try to use any link on the sub-directory (linked to a different domain name), it is always giving me a 404 error. 现在,我的主站点运行良好,但是当我尝试使用子目录上的任何链接(链接到另一个域名)时,它总是给我一个404错误。

I have tried the solution given on Stackoverflow, but it does not work. 我已经尝试过Stackoverflow上给出的解决方案,但是它不起作用。

Duplicate of: CodeIgniter won't run in a subdirectory 重复的: CodeIgniter不会在子目录中运行

So my structure is: 所以我的结构是:

/system
/application1
/index.php
/.htaccess
/development/application2
/development/index.php
/development/.htaccess

The top level .htaccess contains: 顶级.htaccess包含:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ index.php/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

The sub-directory .htaccess is: 子目录.htaccess是:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /development/

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule> 

(I have even tried the suggestions given on StackOverflow to add a ./ in front of the INDEX.PHP files, and the suggestions provided in the other ticket) (我什至尝试了在StackOverflow上给出的建议,以在INDEX.PHP文件前面添加./,以及其他故障单中提供的建议)

The $system_path in the sub-directory points to the top level /system folder, so as to avoid any conflicts. 子目录中的$ system_path指向顶层/ system文件夹,以避免发生任何冲突。

The main page displays correctly on the site, & even the main page of the sub-domain, created as: 主页可以正确显示在网站上,甚至可以正确显示为以下子域的主页:

http://www.mysite.co/ 
http://development.mysite.co/

But any links from the sub-domain created show the 404 error and I have not been able to get any of the links working. 但是创建的子域中的任何链接都显示404错误,但我无法使任何链接正常工作。

I am hosting on a shared server (Linux) on GoDaddy and have PHP 5.3 installed. 我在GoDaddy的共享服务器(Linux)上托管,并安装了PHP 5.3。 The main root is at a location (absolute path): /home/content/22/88885555/html 主根位于以下位置(绝对路径):/ home / content / 22/88885555 / html

And the sub-directory I have created is at (absolute path): /home/content/22/88885555/html/development 我创建的子目录位于(绝对路径):/ home / content / 22/88885555 / html / development

I have used the paths as: 我将路径用作:

/
/development/

Does anyone have knowledge of or has experimented with such a setup? 有谁知道或尝试过这种设置?

Within /index.php modify the following lines: 在/index.php中,修改以下行:

$system_path = "/path/to/your/public_html/system";
$application_folder = "/path/to/your/public_html/application1";

Now edit /application1/config/config.php 现在编辑/application1/config/config.php

Find the following lines and change to your domain name. 找到以下几行,然后更改为您的域名。

$config['base_url'] = 'http://mysite.co';
$config['index_page'] = ''; 

Open up /.htaccess and amend to the following: 打开/.htaccess并修改以下内容:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

ReWriteCond %{HTTP_HOST} mysite.co
RewriteCond $1 !^(index\.php|development)
ReWriteRule ^(.*)$ /index.php/$1 [L]

ReWriteCond %{HTTP_HOST} development.mysite.co
ReWriteCond %{REQUEST_URI} !development/

ReWriteRule ^(.*)$ development/index.php/$1 [L]

Now for your sub directory application. 现在为您的子目录应用程序。

Open up /development/index.php 打开/development/index.php

Amend the following lines to match your setup: 修改以下几行以符合您的设置:

$system_path = "/path/to/your/public_html/system";
$application_folder = "/path/to/your/public_html/development/application2";

Notice the system_path is the same as application1? 注意system_path与application1相同吗?

Modify the config file of application2. 修改application2的配置文件。 Open up /development/application2/config/config.php and amend the base url to your test site. 打开/development/application2/config/config.php并将基本URL修改为测试站点。

$config['base_url'] = 'http://development.mysite.co';

Finally remove, /development/.htaccess. 最后删除/development/.htaccess。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM