how to make multi site with one codeigniter application? - codeigniter

I'm trying to develop a shopping system with codeigniter.
I developing the back-end & front-end of my shopping system.
But my problem is I want to use this code for many stores.
For example my main address is shop.com.
I want people can have their own shop in my system with their own subfolder like this: shop.com/shop1 | shop.com/shop2 & ...
I want the users subfolder placed out of application folder.
My directory list like this:
shop.com
-application
--cache
--config
--controllers
--core
--helpers
--...(other application contents)
-assets
-attachments
-system
-shop1
-shop2
& ...
I making all shop parts and every thing is ok when i call shop.com.
Now I want to making shop1 with specific subfolder and database.
I can making separate database for each shop and connect the code to his own database. after this I call shop.com/shop1 and the main page load like a charm.
But when I call shop controllers ( example: shop.com/shop1/checkout ) I get 404 error.
And at the end I noticed two point:
1- I use the original codeigniter root index.php code as my shop1/index.php
2- I change the $system_path to ../system and $application_folder to ../application
It seems codeigniter unable to locate the controllers properly.
What can I do to solving this problem?

You mean HMVC?
Download files and copy C.i.3.0 forder in application : https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads
Create and coppy paste in .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
3.Create folder name 'modules' in application/
4.Create folder name 'folder' in application/modules
4.Create folder name 'controllers, models, views' in application/modules/folder
5.Create file name 'file name same folder' in application/modules/folder/controllers
for error
paste this in MX/Loder.php
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));

Related

How to setup a Laravel app in a subdomain-directory in a shared host?

I want to access my Laravel application through a directory in a subdomain in a shared host; as in sub.domain.com/dir. I want to be able to properly hit the app routes as sub.domain.com/dir/posts.
Thus, I've set the APP_URL=https://sub.domain.com/dir/ in the .env file. It works through sub.domain.com/dir/public; but the relatively-addressed media are inaccessible; they are referenced as sub.domain.com/path/to/asset, while they should be sub.domain.com/dir/path/to/asset:
sub.domain.com/dir/path/to/asset <--- accessable: Expected
sub.domain.com/path/to/asset <--- inaccessable: What is given
In an attempt to drop the /public part, I've put the following code in an .htaccess file inside of <docroot>/dir directory:
RewriteEngine On
RewriteRule ^(.*)$ /dir/public/$1 [L,QSA]
It seems to be effective on dropping the /public part (let me know if there are issues with that).
Here is the main issue: considering the web.php file to be like:
Route::get('/{num}', function ($num) { return "Number: $num"; })->where('num', '\d+');
Route::get('/{any}', function ($any) { return "Other: $any"; })->where('any', '.*');
Accessing sub.domain.com/dir/123, gets Other: dir/123 instead of Number: 123: Laravel considers the /dir/123 as the routing matter, while I want it to treat the /123 as the routing matter. The same issue causes the assets to not to originate from sub.domain.com/dir but rather from the subdomain root: sub.domain.com, without the /dir suffix).
I want the sub.domain.com/dir to be considered as a whole (as if the /dir is part of the domain, in that the relatively-addressed media would be accessible); and what follows the /dir part, to be fed into Laravel app for routing and all the other stuff.
So, how should I setup my Laravel app in a subdomain-directory in shared host?
Put these lines of code in your laravel root directory .htaccess file, which might be in your sub.domain.com/dir directory.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
that will solve your /public problem.
For the Media assets, did you used the asset URL helper function to link the media assets?

Laravel 4.2 rewrite URL - remove public

My old domain: domain.com
My laravel project in: domain.com/laravel/public
It's working well, but I don't want see public in URL.
I add new .htaccess file to my root laravel folder (domain.com/laravel/.htaccess) with:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
When I access to domain.com/laravel, my jQuery path is: domain.com/js/jquery.min.js
When I access to domain.com/laravel/public, my jQuery path is: domain.com/laravel/public/js/jquery.min.js
I don't want move all files in public folder to root folder, because really more files there.
Best regards,
I read more answers in more website, almost their said move all files in public folder to root folder of Laravel application.
It's not good if we have more files there, so, I was try with some way and finally, I just move index.php and .htaccess file to root application.
It's working well, I just change some code when using HTML::script, HTML::css and {{ asset }}
As normal, we using HTML::css('style.css'), I just add public before, like this: HTML::css('public/style.css')
I hope it helpful for someone.
Best regards.
This is my current solution:
<IfModule mod_rewrite.c>
RewriteCond $1 !^(public)
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>
You have to add a rewrite condition.

Image relative and absolute path and .htaccess

Hy all,
I'm playing around in Codeigneter and trying to make some kind of photo album just for fun ( to understand codeigneter better before i start for real ).
Now did i set up a test website here:
http://foal.scriptsenprogs.nl/
Now the thing is that users can upload an image in the future. And i want that image to be some kind of save...
So if somebody use this link:
http://foal.scriptsenprogs.nl/media/img/albums/1.png
It should be blocked (like it is now).
I've got this line of code in an .htacces file that is placed in /media/img/albums folder
<Directory "http://foal.scriptsenprogs.nl/media/img/albums" >
Options Includes
AllowOverride All
Order allow,deny
Deny from All
</Directory>
I must confess that i have little know-how about .htaccess files, but this seems to work ( the direct url is blocked ).
In my codeIgneter code i use this to add an image to an webpage:
$str .= '<div style="margin-top:20px;"><img width="200px" src="./media/img/albums/' . $imageStuff[$row['album_id']] -> img_id . '.' . $imageStuff[$row['album_id']] -> img_type . '" /></div>';
And before the .htaccess file, it worked. But now it isn't working.
If i check chromes error console i see this error:
GET http://foal.scriptsenprogs.nl/media/img/albums/1.png 404 (Not Found) foal.scriptsenprogs.nl:48
So an 404 Not Found error it is then. But if you check the URL you see that it is conferted to an Absolute URL? But i inserted an Relative URL right?
Any thoughts of you guys on how to fix this?
EDIT 1
In de webroot of the subdomain, i've got the following .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|school|media|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
EDIT 2
To clarify the question something more...
If your on the website ( http://foal.scriptsenprogs.nl/ ) the image must be showable done by using an relative path. ( like this: <img width="200px" src="./media/img/albums/1.png" /> )
But if your trying to acces the image through an absolute path, it must be blocked ( the link will be something like this then: http://foal.scriptsenprogs.nl/media/img/albums/1.png )
Sometimes CI and relative urls don't play nice together, try using the base_url function
'src="'.base_url().'media/img/albums/'
You could add a new rule to your existing webroot/.htaccess file.
Place the following after the RewriteEngine On line towards the top of your file.
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yoursite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png|jpg)$ /404.html [L]
This restricts access to any jpg,gif, etc to the domain http://yoursite.com, other requests are redirected to a 404 page.
NOTE: If you are testing this on a local server, you will be on the same domain as your site so it will most likely seem like nothing is happening.

.htaccess will not redirect .php files

I have this in my htaccess, standard domain redirection:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ "http\:\/\/fullnewdomain\.org\/$1" [QSA,R=301,L]
And it works fine for folders, subfolders, html files, images, etc. However, for some reason it refuses to redirect php files. Instead they still run as normal and do not redirect to the new domain. Any ideas as to why, and how I can fix it? It's almost like this host is trying to execute the php file before checking any rules ( And I'm not sure what I could do if that's the case! ).
Turns out there was an htaccess file the host had placed in the home directory ( One level above public_html ) to "counter" bots, but all it did was break anything else that tried to apply a rule to php files. Removed the file, problem solved itself.
For reference, hostgator was the host, and I still don't know why they felt the need to place the file there in the first place.

Directory Structure and Mod_Rewrite

I designed a php/mysql/query based on the idea of a subdirectory per function, so my directory structure looks like this:
public_html\
..users\ (all user related files are in this folder)
..events\ (all event related files are in this folder)
..groups\ (all group related files are in this folder)
..layouts\ (global header, global footer, and global navigation include files are in here)
Any pages in the users,events or groups folder include the header, footer and navigation files so they all keep a theme. Because of this the navigation file has all links set to
../functionfolder/file.php" and it works out because you are usually in one of the function folders.
But I forgot the index file in the public_html, when I include my headers, footers and nav from that directory (not being a sub folder) the "../"'s mess every thing up.
I have already created a separate navigation file that will make files in the high level directory work but I realized that all of my pictures and script includes are messed up.
(created a separate nav include with no ".."'s)
What I think may be a solution:
do not use a index.php file home director but create a directory named home and place the index file in there so everything will work out.
(public_html/home/index.php vs public_html/index.php)
(not sure how that would work out with the domain)
I have also looked at absolute vs relative links but they end up being a mess working on my computer then uploading them??
Anyone have an Ideas that can help?
Update:
would something like this work?
# Turn on rewrites.
RewriteEngine on
# Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
# Only apply to URLs that aren't already under folder.
RewriteCond %{REQUEST_URI} !^/folder/
# Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all those to insert /folder.
RewriteRule ^(.*)$ /folder/$1
# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ folder/index.php [L]

Resources