【问题标题】:.htaccess codeigniter multiple domains.htaccess codeigniter 多个域
【发布时间】:2011-04-15 03:26:25
【问题描述】:

我想知道是否可以组织CodeIgniter安装的以下结构:

- Main folder
-- codeigniter
-- images
-- site1-application
-- site2-application
-- site1-index.php
-- site2-index.php

主要思想是在多个网站上使用相同的 imagescodeigniter 文件夹,以便于维护。

目前我确实有两个网站,它们位于两个标准安装中,我无法共享图像文件夹,也无法在多个网站上同时更新系统库。

我玩过 .htaccess 文件,但运气不好 :(

提前致谢!

【问题讨论】:

    标签: .htaccess codeigniter multiple-sites


    【解决方案1】:

    默认推荐 CodeIgniter .htaccess 文件:

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
    
      #CodeIgniter
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ /index.php/$1 [L]
      RewriteRule ^$ /index.php [L]
    </IfModule>
    

    为您的目的调整 CI .htaccess 文件(您知道,晚了一年):

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
    
      #CodeIgniter
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
    
      # Check for Domain 1 with a path
      RewriteCond %{HTTP_HOST} domain-1.com
      RewriteRule ^(.*)$ /site1-index.php/$1 [L]
      # Check for Domain 1 without a path
      RewriteCond %{HTTP_HOST} domain-1.com
      RewriteRule ^$ /site1-index.php [L]
    
      # Check for Domain 2 with a path
      RewriteCond %{HTTP_HOST} domain-2.com
      RewriteRule ^(.*)$ /site2-index.php/$1 [L]
      # Check for Domain 2 without a path
      RewriteCond %{HTTP_HOST} domain-2.com
      RewriteRule ^$ /site2-index.php [L]
    </IfModule>
    

    【讨论】:

    • 这对我有用,但我必须在域 1 和域 2 之间添加另一个 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d(空行)
    【解决方案2】:

    是的,这是可能的。

    使用 .htaccess 将所有流量从一个域定向到 site1-index.php,并将所有流量从另一个域定向到 site2-index.php。

    CI 应用程序和系统文件夹的位置在 *-index.php 文件中设置。

    【讨论】:

    • 感谢您的回答。请您帮我处理 .htaccess 脚本,因为它们看起来像巫术而不是编程?
    猜你喜欢
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 2014-02-21
    相关资源
    最近更新 更多