Dan Hastings
Dan Hastings

Reputation: 3290

Remove index.php From Sub directory websites URL

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?

Upvotes: 1

Views: 1913

Answers (2)

PiranhaGeorge
PiranhaGeorge

Reputation: 999

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]

Upvotes: 2

Nirav Patel
Nirav Patel

Reputation: 85

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.

Upvotes: 0

Related Questions