Jump to content

Recommended Posts

Hey everyone, I have a question (it's a crazy one) and am hoping to hear some feedback on what I have been developing.  Many common MVC frameworks require you to place your website in the root directory of your htdocs folder. If you wanted to add another website (example being maybe a mobile version), you would have to create a sub domain or use clever naming conventions in the controllers and views. I wanted to try and create a way in which I did not have to create a sub domain each time I wanted to create a new site - rather simply just create a new folder and the framework reside and hold multiple applications.

 

So, the biggest issue is handling the paths of images and front end scripts. Every application has its very own public folder. Before I was used to having everything absolute so you would see:

 

/app/default/public/img/tedd.jpg

 

Well when you have multiple sites and applications you end up seeing this:

 

/site1/app/default/public/img/test.jpg

/site1/app2/default/public/img/test.jpg

 

Now when you upload that to your server you are going to have to change the paths of all the images and scripts (because surely you wouldn't want to have to create site1 on your server if it's the only site there). Well I decided to test out an interesting way to access the applications public folder by modifying the htaccess folder. So now instead of writing out this absolute path, I would simply say:

 

_public/img/test.jpg

 

And that would reference the public folder of the application of which you are viewing. I did this so I could have multiple websites on my server without having to create a subdomain each time (especially since mine limits me - shared hosting lol). That's the basic concept and it's achieved by using the <BASE> tag and getting the directory of which the index.php file lyes in (making this the new root folder).

 

Do you think this is overkill or perhaps something quite interesting? Just wondering because sometimes as a developer you will come across some really crazy ideas and they can either be completely innovative or simply overkill.

 

Here's an example of what I had to do in the .htaccess file:

 

### CSS RULES ###

RewriteRule ^(.*)/_public/css/_public/(.*)$ apps/$1/_public/$2 [L]

RewriteRule ^(.*)_public/css/_public/(.*)$ apps/_default/_public/$2 [L]

 

### REGULAR RULES ###

RewriteRule ^(.*)/_public/(.*)$ apps/$1/_public/$2 [L]

RewriteRule ^_public/(.*)$ apps/_default/_public/$1 [L]

RewriteRule ^(.*)/vendors/(.*)$ vendors/$2 [L]

 

Thanks and any advice would be nice. Keep in mind my main goal is to have multiple sites in a directory without having to create a subdomain each time. Thanks!

 

Link to comment
https://forums.phpfreaks.com/topic/242239-mvc-framework-in-subdirectories/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.