简体   繁体   中英

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. eg 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?

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]

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM