【问题标题】:codeigniter multiple applications, with wild card sub domains, mod_rewrite remapping sub domains to .phpcodeigniter 多个应用程序,带有通配符子域,mod_rewrite 将子域重新映射到 .php
【发布时间】:2023-04-09 15:09:01
【问题描述】:

我有一个如下结构的 codeigniter 项目:

httpdocs/
  /application/
    /ggg/
      config/
      controllers/
      models/
      libraries/
      views/
      ...
    /sgaz/
      config/
      controllers/
      models/
      libraries/
      views/
      ...
    /index/
      config/
      controllers/
      models/
      libraries/
      views/
      ...
  /system/
  index.php

我正在尝试重新编写通配符子域以映射到其各自的应用程序。只是不知道该怎么做。

我知道您可以创建多个应用程序并为每个应用程序使用多个 (.*).php 文件(IE:ggg.php、sgaz.php、index.php)。但是是否有可能有一个 index.php 文件并使用 mod_rewrite 将调用从子域重定向到其各自的应用程序环境? IE:http://ggg.mapitusa.com/user/login 重定向(没有 htaccess)到 http://mapitusa.com/index.php/ggg/user/login?

谢谢!

【问题讨论】:

    标签: php apache codeigniter mod-rewrite


    【解决方案1】:

    尝试将以下内容添加到站点根目录中的.htaccess 文件中。

    RewriteEngine on
    RewriteBase / 
    
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.mapitusa\.com$ [NC] 
    #if not existing file or directory
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d
    #rewrite to index.php
    RewriteRule ^ index.php/%1%REQUEST_URI] [L] 
    

    如果希望地址栏中的 URL 更改为http://mapitusa.com/index.php/ggg/user/login?,请将上面的 RewriteRule 替换为

    RewriteRule ^ http://mapitusa.com/index.php/%1%REQUEST_URI] [L,R=301] 
    

    【讨论】:

      猜你喜欢
      • 2022-08-15
      • 2017-05-10
      • 2010-09-18
      • 2011-12-29
      • 2011-08-19
      • 1970-01-01
      • 2013-02-16
      • 2012-10-31
      • 2011-06-16
      相关资源
      最近更新 更多