1

I am currently in the process of moving a large number of subdomain websites to become sub directory websites. e.g. site1.website.com => website.com/site1. All of these sites use the same code in the same directory. The code will read the site name and load the correct database if it exists. So i have the following alias formatting for all sites.

Alias  /site1 /var/www/laravel/public 

Without needing to explain too much, laravel is an MVC framework and index.php is the only file that i need to route traffic through. Because of this all of the URLS need to have index.php as a prefix, but this is really ugly and i cant seem to get rid of it.

I tried the following which worked when the website was a subdomain, but it doesnt work now. When i use this code website.com/site1/login will redirect to website.com/login.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

All websites are dynamic so i dont want to hardcode a rule for every single website. Is there a way i can handle this?

Dan Hastings
  • 3,241
  • 7
  • 34
  • 71

2 Answers2

2

Set a RewriteBase for the new folder, like so:

RewriteEngine On
RewriteBase /site1/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
PiranhaGeorge
  • 999
  • 7
  • 13
  • awesome! this worked. Do you know if its possible to do this dynamically? I have a lot of subdomains and i will be adding more in the future so it would be nice if i didnt have to add a new one each time. – Dan Hastings Jun 21 '15 at 10:47
  • I misread your question before. I'm not really use why `RewriteBase /` wouldn't work. Surely Laravel will deal with the directories for you? – PiranhaGeorge Jun 21 '15 at 10:57
  • for some reason when i set RewriteBase / it will just display the home page from the main website. Your above code has worked perfectly, its just a lot of manual code to write so if i could set the base dynamically it would be perfect. i have root access to the server so i can change anything i need to in apaches conf files – Dan Hastings Jun 21 '15 at 11:00
  • I found http://stackoverflow.com/questions/21062290/set-rewritebase-to-the-current-folder-path-dynamically does this do it? – PiranhaGeorge Jun 21 '15 at 11:10
  • actually this worked! RewriteRule ^ %{ENV:BASE}/index.php [L] . i removed the reqwritebase completely – Dan Hastings Jun 21 '15 at 11:22
0

you can manage connection from laravel\config\database.php for your each site.

then you can set all sub domain will be point on one location, now you need to update update just database.php when you add new website.