Magento multi website controller - magento

Is it possible to programmatically dispatch websites in Magento? Currently, I have a directory in the root of my site called /websites. In this directory I have subdirectories for each website, for example, site_a, site_b, site_c. Then each site subdirectory has a .htaccess and index.php with appropriate run code, for example:
$mageFilename = '../../app/Mage.php';
require_once $mageFilename;
Mage::run("site_b", "website");
in the index.php in /websites/site_b. While this works, I do wish to avoid doing file management in the filesystem. Anyone can give any recommendation on the best way to do this? Perhaps a script in /websites that stands in place of the individual site sub directories. Any help appreciated.

You have access to the $_SERVER variables in php and you can use these to determine the Mage::run("whatever", "website"); call, e.g.:
$whatever=$_SERVER['condition/url/whatever'];
// or use some cookies
if (isset($_COOKIE['dev'])) $whatever=$_COOKIE['dev'];
switch($whatever)
{ case "example.com":
case "www.example.com":
$_SERVER['MAGE_RUN_CODE'] = "example";
$_SERVER['MAGE_RUN_TYPE'] = "website";
break;
case "dev":
case "test.com":
$_SERVER['MAGE_RUN_CODE'] = "test";
$_SERVER['MAGE_RUN_TYPE'] = "website";
default:
$_SERVER['MAGE_RUN_CODE'] = "live";
$_SERVER['MAGE_RUN_TYPE'] = "website";
}
Mage::run($_SERVER['MAGE_RUN_CODE'], $_SERVER['MAGE_RUN_TYPE']);
In this way you only need one code base plus correctly configured settings in Magento backend to route to your different stores.

You can handle all in .htaccess file
mine looks like this:
#SetEnvIf Host www\.lenjerii\.com MAGE_RUN_CODE=base
#SetEnvIf Host www\.lenjerii\.com MAGE_RUN_TYPE=website
#SetEnvIf Host ^lenjerii\.com MAGE_RUN_CODE=base
#SetEnvIf Host ^lenjerii\.com MAGE_RUN_TYPE=website
#SetEnvIf Host www\.wildfashion\.ro MAGE_RUN_CODE=wildfashion
#SetEnvIf Host www\.wildfashion\.ro MAGE_RUN_TYPE=website
#SetEnvIf Host ^wildfashion\.ro MAGE_RUN_CODE=wildfashion
#SetEnvIf Host ^wildfashion\.ro MAGE_RUN_TYPE=website
This solution eliminate any other folders for your additional websites.

if I understand you correctly, what you need are some symbolic link: in each subdirectory, make symbolic link to the original installation. IE: ln -s ../app/ ./app.
Check out this tutorial

Related

CodeIgniter in Ubuntu 16.04

I'm trying to move my CI project from my localhost in windows to Ubuntu. I'm working with:
In my cognfig.php
$config['base_url'] = '';
$config['index_page'] = 'index.php';
My Virtual Host:
<VirtualHost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin mymail#mymail.com
ServerName mywebiml.com
ServerAlias www.mywebiml.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.php
DocumentRoot /var/www/html/CLASE
</VirtualHost>
The root folder of the CI application is "CLASE".
Also, I added entries in /etc/hosts
MyIp mywebiml.com
MyIp www.mywebiml.com
The problem being, I keep getting the custom 404 error from CI when I try access my page.
First you MUST give $config['base_url'] a value. Use the following
$config['base_url'] = 'http://mywebiml.com/';
Second, make sure you are using the file and class naming scheme CI requires. Class files must be named in a Ucfirst-like manner, while any other file name (configurations, views, generic scripts, etc.) should be in all lowercase.
Bad:
some_class.php
Good:
Some_class.php
Class names should always start with an uppercase letter. Multiple words should be separated with an underscore, and not CamelCased.
Bad:
class someClass {
Good:
class Some_class {
File names and class names must be exactly the same - case-sensitive.
The above rules won't matter on a Windows based development environment but will on a linux system like Ubuntu.
If you are using .htaccess to rewrite URLs so the index.php is removed use the following.
$config['index_page'] = '';

Codeigniter - 1 project - several domain names and several IP

I have 1 dedicated server.
The server has several IPs.
Some IP are dedicated for one particular domain.
Ip1 = mysite.be
Ip2 = mysite.fr
Ip3 = mysite.com
There is only one project. Each domain goes on the same location
My website is on /var/www/vhosts/mysite.com/httpdocs
For all other domain, i create a symlink.
/var/www/vhosts/mysite.be/httpdocs -> /var/www/vhosts/mysite.com/httpdocs
/var/www/vhosts/mysite.fr/httpdocs -> /var/www/vhosts/mysite.com/httpdocs
...
When I go on mysite.com, all works.
But when i go on mysite.be ... I have an output from codeIgniter :
No input file specified.
I search more information about this error and I see that : https://stackoverflow.com/a/14578219/905867
My .htaccess fil is already well configured... I guess
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|css|js|uploads|modules|public|timthumb\.php|\.htpasswd|google.*\.html|captcha)
RewriteRule ^(.*)$ /index.php?/$1 [L]
The fact that the domain linked with symlink display the error "No input file specified." proves that the symlink is OK and the acl on server are OK too (chown and chmod).
I think it's a little thing, but i don't know what. Anyone has a idea please ?
Some others information :
- I manage my server with plesk 11.0.9 #53
- My domain are "php as FastCGI module". If I use "as Apache Module, there is a blank page instead of error "No input file specified."
It takes me long time but... problem is solved.
No input file specified wasn't a CodeIgniter error but a CGI/FastCGI error...
So I check on my plesk an I saw the domain are "PHP as FastCGI module" instead of "PHP as Apache Module".
But... instead of an error, I have a blank page.
Then I thought about open_basedir restriction. It was configured on "Webspaceroot" instead of "Docroot"... and "abracadabra" it works.
Take care !

url rewrite debian

I just got fresh debian VPS into my hands.
I installed url rewrite and simple things like this does seem to work
RewriteRule ^login$ /login.php
However this doesn't work:
RewriteRule ^cats$ /index.php?cat=cats
Anyone have idea why?
(it works on local xampp server + it worked on shared host I had)
Thanks
First of all make sure that you have mod_rewrite, and it's on. To do so, create an empty Php file, then add <? phpinfo() ?> and diplay it in your browser.
If it's "on" then you can go on.
If it's in a .htaccess file then try with / without the slashes.
RewriteRule ^cats$ /index.php?cat=cats
Or
RewriteRule ^/cats$ /index.php?cat=cats
And if that's not enough:
Two hints:
If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the .htaccess files), try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)

Reaching files outside od the documentroot scope

I'm writing a script to build a dynamic website,
the website is created by loading external components.
The DocumentRoot is location at /sites/website/public
the components directory is located at /sites/website/components
i wannna reach the data directory of each component depends on the requested url.
for example:
the url:
http://ibuildmywebsite/component-data/randomimage/demo/swan04090044_small.jpg
should fetch the file /sites/website/components/randomimage/data/demo/swan04090044_small.jpg
how can i achieve that ?
i would prefer a way that can be placed inside .htaccess (if there is one) instead of modifying the virtual host definitions.
Thanks!
Combine RewriteRule with Alias maybe ?
Alias /randomimage /sites/website/components/randomimage
RewriteRule ^component-(.*)/randomimage/(.*)$ /randomimage/$1/$2 [R,L]
(Won't work in .htaccess though)
You could probably also use Symlinks with:
Options +FollowSymLinks
And link dynamically components-*/randommimage/* to /sites/website/components/randomimage/*/*/

Installing a CodeIgniter application in a subfolder

I'm trying to install an application made with codeIgniter in a subfolder, so that I can access it using : http://www.domain.com/my_subfolder/
At the root, there's a Wordpress application.
I edited the .htaccess of the Wordpress install to let the request go to the folder /my_subfolder/
It's working fine, the only problem I get is that CodeIgniter is unable to dynamically load the classes in the "libraries" directory. So everything in the CI application works fine until it tries to use an object declared in the "libraries" subfolder, then I get a : Unable to load the requested class: my_class
It doesn't seems that there's a parameter in the "config" folder to change that... any idea?
What you need is to edit your CodeIgniter config.php in System > application > config.
and then edit config.php and set the property:
$config['base_url'] = "http://www.domain.com/my_subfolder/"
Well it seems that the config param base_url should be updated. Also, I used a library with the "MY_" prefix, and I should'nt since I was'nt extending any CI class.
This is 2021. In case anyone is having this same issue with CodeIgniter 4, this is how I solved it when I came across this issue.
Problem
I installed CI in a subfolder in my public_html folder i.e example.com/api. When I visited www.example.com/api, I saw a 403 forbidden error.
Solution
Download and unzip CI on your local machine or use composer.
Rename public folder to the name of your subfolder. In my case, I named it api.
Create another folder and give it any name of choice, for example, let's use mango (yes, I love mangoes). Copy all the remaining files and folders (app, system, writables, env, LICENSE, README, composer, phpunit, spark) into the mango folder. After doing this, we should have 2 folders: api and mango
Copy both folders to your live server cpanel root (Do not copy into public_html or www). Let them be on the same level as public_html
Open api/index.php and change $pathsConfig = FCPATH . '../app/Config/Paths.php'; to $pathsConfig = FCPATH . '../mango/app/Config/Paths.php';
Create a subdomain and point it to /api
Go to the api folder, duplicate the env file and rename it to .env
Open .env and look for app.baseURL=''. Remove the '#' to uncomment that line and the change it to app.baseUrl='http://subdomain' where subdomain is the subdomain you created above e.g http://api.example.com
Open mango/app/config/App.php and look for public $baseUrl and set it to subdomain e.g $baseUrl = 'http://api.example.com'
Your CI project is now well configured. Visit http://api.example.com. and you should see the CodeIgniter welcome page.

Resources