Changing root folder to /web for Drupal 9/10 in Apache.

When you create a Drupal Project using the composer, it creates two root folders: vendor and web. The web folder contains the developed website, and the vendor folder has dependencies and vendor libraries. When you try to make this website live with the same directory structure, website URL container /web in every URL, which is not a good practice, to remove the /web from the path, you need to tell the Apache server to send all the request to the web folder and web folder must be considered as the root folder for the website.

Here is the .htaccess file which can help you to achieve that.


RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mywebsite.com$
RewriteCond %{REQUEST_URI} !^/web/
RewriteRule ^(.*)$ /web/$1
RewriteCond %{HTTP_HOST} ^(www.)?mywebsite.com$
RewriteRule ^(/)?$ web/index.php [L]