简体   繁体   English

从子目录网站URL删除index.php

[英]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. 例如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. 无需过多解释,laravel是一个MVC框架,而index.php是我需要路由流量的唯一文件。 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. 因此,所有URL都需要具有index.php作为前缀,但这确实很丑陋,我似乎无法摆脱它。

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. 当我使用此代码时,website.com / site1 / login将重定向到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: 为新文件夹设置一个RewriteBase,如下所示:

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. 您可以从每个站点的laravel \\ config \\ database.php管理连接。

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. 然后就可以设置所有子域名将在一个位置点,现在你只是需要database.php中更新更新,当您添加新的网站。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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