本文介绍了codeigniter多个应用程序,用通配符子域名,重新映射mod_rewrite的子域的.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个codeigniter项目结构为这样:

I have a codeigniter project structured as so:

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

我想重新写一个通配符子网域映射到其各自的应用..只是不知道如何去了解这一点。

I am trying to re write a wildcard sub domain to map to its respective application.. Just not sure how to go about this.

我知道你可以创建多个应用程序和使用多个为每个应用程序的PHP文件(即:ggg.php,sgaz.php,的index.php)(*)。但有可能有一个单一的index.php文件,并使用mod_rewrite将呼叫从一个子域到各自的应用程序ENV重定向? IE:重定向(不htaccess的),以 ?

I know you can create multiple applications and use multiple (.*).php files for each application (IE: ggg.php, sgaz.php, index.php). But Is it possible have a single index.php file and use mod_rewrite to redirect calls from a sub domain to its respective application env? IE: http://ggg.mapitusa.com/user/login redirects (without htaccess) to http://mapitusa.com/index.php/ggg/user/login?

谢谢!

推荐答案

尝试添加以下到您的网站的根目录下的的.htaccess 文件。

Try adding the following to the .htaccess file in the root directory of your site.

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?,更换重写规则以上

If you want the URL in the address bar to change to http://mapitusa.com/index.php/ggg/user/login?, replace the RewriteRule above with

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

这篇关于codeigniter多个应用程序,用通配符子域名,重新映射mod_rewrite的子域的.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 19:00