0

I have a requirement where I need to run two separate applications using codeigniter 3.11 where one is already running from root directory and other one should be run from a subdirectory on same server and domain. I have following limitations

  1. I can't have a subdomain
  2. I can't have virtual host setting where in both applications run on their own directory like example.com/site1 and example.com/site2. Because already site1 is use in public from many years and running from root like example.com will show site1. Now I can't ask users to use example.com/site1 instead of example.com.
  3. I can't use 2 separate application folders because main application is having many files outside application folder also. The 2nd application is only for few users and entirely independent. But it should be available under the url example.com/site2. Please guide me how to achieve it.

This is what I have done as of now.

  1. Created a directory entry inside apache conf that refers to site2.
  2. Tried to use the htaccess to make site2 working but couldn't. Tried different htaccess changes but they need a subdomain to work which I can't have.
  3. Currently having default htaccess file for CI 3.11.

Changes I made to

Virtualhosts

set DocumentRoot /var/www 
Alias / /var/www/html 
<Directory /var/www/html>
  Options -Indexes +FollowSymLinks +MultiViews
  AllowOverride All
  Require all granted
</Directory> 
Alias /site2 /var/www/site2 
<Directory /var/www/site2> 
 Options -Indexes +FollowSymLinks +MultiViews
 AllowOverride All
 Require all granted
</Directory> 

site1 .htaccess

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule> 

.htaccess site2

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /site2/ 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

But both sites won't work if I try like below

http://site1 -- Forbidden 
http://site1/site2 -- The requested URL was not found on this server

I am expecting the site1 to show up when example.com is visited and site2 to show up when example.com/site2 is visited.

Any help is highly appreciated.

Thanks

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
  • Doesn't CI have a config param called "base_url"? If so, try setting that to the url to the subfolder and add a [`RewriteBase /site2/`](https://stackoverflow.com/questions/704102/how-does-rewritebase-work-in-htaccess) after your `RewriteEngine On` in site2's htaccess (CI's default htaccess in site2) – M. Eriksson Jul 24 '23 at 09:15
  • read https://codeigniter.com/userguide3/general/managing_apps.html – totoprayogo1916 Jul 24 '23 at 15:40
  • @M.Eriksson it has base_url. But it is not working. – Aravinda B N Jul 25 '23 at 07:15
  • @totoprayogo1916 I referred to it, but that is also not working. Main issue here is that primary application should run from root. Sub application from subfolder. – Aravinda B N Jul 25 '23 at 07:17
  • You need to show us how you implemented it and give some details what you mean by "not working" (which doesn't really tell us anything). Btw, did you try RewriteBase as well? We need to know the details. What actually happens? Errors? Wrong site? 404 response? 500 response? Something else? – M. Eriksson Jul 25 '23 at 07:49
  • @M.Eriksson I did like this. virtualhosts. set DocumentRoot /var/www Alias / /var/www/html -- relevant lines Alias /site2 /var/www/site2 -- relevant lines site1 .htaccess -- default CI3 .htaccess site2 .htaccess default CI3 .htaccess RewriteBase /site2/ But both sites won't work if I try like below http://site1 -- Forbidden http://site1/site2 -- The requested URL was not found on this server. – Aravinda B N Jul 25 '23 at 10:56
  • ---Continued But if I comment "Alias / /var/www/html " in the virtualhost http://site1/site2 will be working. But http://site1/ -- Forbidden. Please suggest. – Aravinda B N Jul 25 '23 at 10:56
  • Please [edit](https://stackoverflow.com/posts/76752291/edit) your question to include all necessary information. – M. Eriksson Jul 25 '23 at 13:04
  • Why do set the document root as `/var/www` just to alias the root `/` to `/var/www/html`? Why not just set `/var/www/html` as the document root instead? And then just have one alias for site2? Please add the vhost settings to the question without replacing the contents of the sections with "--relevant lines". The same goes for your htaccess. We need to get the full picture of how things are set up. – M. Eriksson Jul 25 '23 at 13:08
  • @M.Eriksson I edited the question. I didn't set document root because site2 is in folder /var/www/site2 and not /var/www/site1/site2 . – Aravinda B N Jul 26 '23 at 04:56
  • If you have the document root to the main site (site1), all you need to do is to set an alias for site2. – M. Eriksson Jul 26 '23 at 06:40
  • @totoprayogo1916 I tried this approach but I couldn't find how both applications are called and configured. Can you suggest some link where it is demonstrated with config files available for reference. Unless it is decided at the beginning I don't think we may merge two CI applications in that approach. Means one of or both applications may have files stored outside application folder. Please suggest and share the link if possible. – Aravinda B N Jul 27 '23 at 09:04
  • @AravindaBN : I create simple CI3 multi app, see https://github.com/totoprayogo1916/ci3-multiapp ... for screenshots : https://github.com/totoprayogo1916/ci3-multiapp/discussions/2 || sorry, I dont know the mean of limitations number 3. – totoprayogo1916 Jul 27 '23 at 11:39
  • @M.Eriksson Thanks for the help. If you put your comment as an answer. I can mark it as resolved. – Aravinda B N Jul 28 '23 at 11:27

0 Answers0