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?

7
  • Can you try this ? Commented Jun 21, 2015 at 10:26
  • this kind of worked. The urls arent redirecting to the main website, but its still giving a 404 error. The requested URL /site1/login was not found on this server. Commented Jun 21, 2015 at 10:34
  • You have regular routes.php or dealing something dynamic in it ? Commented Jun 21, 2015 at 10:37
  • just regular routes.php. The only thing that i have dynamic is the database connection. everything else worked just fine when it was a subdomain Commented Jun 21, 2015 at 10:39
  • You have .htaccess in your root or home folder ? Commented Jun 21, 2015 at 10:41

2 Answers 2

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]
Sign up to request clarification or add additional context in comments.

5 Comments

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.
I misread your question before. I'm not really use why RewriteBase / wouldn't work. Surely Laravel will deal with the directories for you?
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
actually this worked! RewriteRule ^ %{ENV:BASE}/index.php [L] . i removed the reqwritebase completely
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.

1 Comment

the database isnt the issue its index.php in the url. the database connections are working fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.