【问题标题】:How to write a .htaccess to access multiple CodeIgniter projects in different environments?如何编写 .htaccess 来访问不同环境中的多个 CodeIgniter 项目?
【发布时间】:2013-10-08 13:35:36
【问题描述】:

我有两个 CodeIgniter v2.1.4 项目在 2 个单独的子目录中运行,即 devprod。下面是文件结构:

/ (root)
.htaccess (01)
  - dev
      - .htaccess (02)
      - application
      - system
      - assets
          - js
          - css
          - img
  - prod
      - .htaccess (03)
      - applications
      - system
      - assets
          - js
          - css
          - img

我想做的是

  • 如果用户访问 www.abc.com,用户将重定向到 www.abc.com/prod,将 prod 隐藏在 URL 中.
  • 如果用户访问 www.abc.com/prod,用户将被重定向到 www.abc.com/prodprod 是显示在 URL 中。
  • 如果用户访问www.abc.com/dev,用户将被重定向到www.abc.com/dev,无需隐藏dev 在 URL 中。

下面是我的.htaccess (01)

RewriteEngine On
RewriteBase /prod
RewriteRule ^(.*)$ /prod/index.php?/$1 [L]

.htaccess (02)

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|assets|robots\.txt|changelog\.html)
RewriteRule ^(.*)$ /dev/index.php?/$1 [L]

.htaccess (03)

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|assets|robots\.txt|changelog\.html)
RewriteRule ^prod/(.*)$ /prod/index.php?/$1 [L]

ISSUE:现在不起作用的是 assets 文件夹中的文件必须在 URL 中包含 devprod 才能加载,例如

  • www.abc.com/prod/assets/js/jquery.js ✔ 它有效!
  • www.abc.com/assets/js/jquery.js × 失败...

【问题讨论】:

    标签: regex .htaccess codeigniter mod-rewrite


    【解决方案1】:

    下面应该是您的 .htaccess (01)

    RewriteEngine On
    
    RewriteRule ^(assets/.*)$ /prod/$1 [L,NC]
    
    RewriteRule !^prod/ /prod/index.php?%{REQUEST_URI} [L,NC]
    

    您可以保留其余代码。

    【讨论】:

      猜你喜欢
      • 2014-10-20
      • 2020-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-31
      • 1970-01-01
      • 2012-10-04
      • 2019-05-04
      相关资源
      最近更新 更多