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.
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 ?
Thanks!
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]
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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.