I’m having a scenario where I had to deploy multiple directories for different languages. Development has initially centered on one of those languages, and just one part of the whole site is a small CI app.
I’m trying to avoid copying the whole app for the several other languages, and redirecting to it with an .htacces. The latter is working fine, but CI returns a 404 error when accessed from a URL different to the real one.
My best guess is that certain configuration files must exist with unique properties that configure the additional root URLs, but I don’t know where to start (and Google didn’t come up with a similar scenario).
File Structure:
public_html/
lang1/
app/
(the actual CI app)
other static stuff...
lang2/
app/
.htaccess (redirecting to /lang1/app/)
other static stuff...
lang3/
...
Additional info:
The $config['base_url'] is set to http://.../lang1/app/.
The .htaccess:
RewriteEngine on
RewriteRule ^(.*)$ /lang1/app/$1 [L]
I was able to accomplish this by my own. For those who might find this question in the future, these are the steps to access your application from a different directory. Considering the scenario introduced in the question above, the following example will work for the deployment of of a ghost version of the app in the
lang2directory:1.- Copy only the index.php file from the root of your CI installation (from
lang1/app/index.php) to thelang2/app/directory.2.- Edit the following lines:
3.- Add any configuration you may want to have set explicitly for said subdirectory, these will be set to $this->config, replacing the values set in the config file in your base application:
4.- You have to set a proper
base_url. In this case, we could reuse thelang_versionconfig we just included. This way, we can forget about this line in the next languages we need to create.5.- Create an
.htaccessfile insidelang2/appto make sure that any static assets (js, css, images) accessed by the HTML are get from the actual assets folder inside the original app directory, like inlang1/app/assets:6.- Add to this
.htaccessyour usual rule to keep your URLs friendly, but this time directing all traffic to the ghost copy of your app:7.- Grab a beer or any other beverage you drink to celebrate success, always respecting your local laws. Profit. Your controllers will have to read the
config('lang_version')value to present the content in the proper language to the user. You may use the included language helper for that, or any other solution you prefer.