Reputation: 365
I developed a web application using Xampp and CodeIgniter. The best way to handle clean routing has been to set the VirtualHost to point on the folder containing the project in xampp/apache/conf/httpd.conf, then using routing routes in the route.php file, e.g.,
$route['page1'] = "Page1Controller/page1Function";
I use href or header like this using root as base folder:
href="/page1"
All that works very well on locally and I never use base_url()
or such functions.
Switching to production server, I obviously don't have any rights except for my personal folder and subfolders so when I execute it, root folder becomes root of all domain, not just my project folder.
I tried base_url()
but it doesn't work, pages aren't found, even when not using $route
.
Is there a way to handle this without refactoring all links in code or what is the way to do it with refactoring?
EDIT
Instead of using "/page1"
, I'm now using "./page1"
to access the location of the index.php folder. However, I'm still not able to access other pages neither with php, nor with html/js.
Upvotes: 1
Views: 246
Reputation: 365
Assuming routing is working on local, here are the steps that I took to adapt it to production server.
1 - First letter capital on Controllers and Views
CodeIgniter is requesting the use of the capital letters in the naming of Controllers and Views so even if routing is working on Windows, Linux case-sensitivity requires the right naming in both the class title and the reference in the routes.php file.
2 - Using './'
instead of '/'
Because the deployment of the application occurs in a subdomain, the root corresponds to the domain itself rather than the subdomain where index.php resides and which is accessible with './'
(cf. SO question).
3 - Hardcoding subdomain path in the .htaccess file
Following this doc, I executed steps to correct the standard .htaccess file to make it work with a sub-directory on the server. The standard variant is simply to remove the '/'
from this rule :
RewriteRule ^(.*)$ /index.php/$1 [L]
which leads to
RewriteRule ^(.*)$ index.php/$1 [L]
However, this hasn't solve it on my server, I had to hardcode the path :
If you are running EE from a sub-directory and it still doesn’t work after removing the slash, you may need to specify the sub-directory in your rewrite rule. For example, if your sub-folder is named testing, change:
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
To:
RewriteRule (.*?)index\.php/*(.*) testing/$1$2 [R=301,NE,L]
And change:
RewriteRule ^(.*)$ /index.php/$1 [L]
To:
RewriteRule ^(.*)$ testing/index.php/$1 [L]
Upvotes: 1