By drupaluser2012 on
Hello,
Recently developed a commerce website using Drupal 8 CMS. Deployed it to the Cpanel server but unable to set the document root as /public_html/web.
so added one index.html file under public_html directory with code below.
<meta http-equiv="refresh" content="0; url=www.domainname.com/web" />
Whenever the site is accessed it goes to /web and all other pages are also getting access using .com/web/page-name
How can I force or set document root to /public_html/web as document root?
Any help will be appreciated.
Thanks,
Comments
My cpanel host (shared
My cpanel host (shared hosting plan) allow you to reset the document root. But then it gives a pretty strong warning that features such as restores from backup won't work right if you do. So, I leave document root at public_html. Have an .htaccess in public_html that does something like:
RewriteOptions inherit RewriteEngine on RewriteCond %{HTTP_HOST} ^yourdomain\.org$ [OR] RewriteCond %{HTTP_HOST} ^www\.yourdomain\.org$ RewriteRule ^/?$ "https\:\/\/yourdomain\.org\/web\/home" [R=301,L]Backup htaccess first and test the new one because an error there can put your site out of business.
For what it's worth, I have composer.json and composer.lock and vendor at the same level as /web.
Thank you for the reply
Thank you for the reply @fkelly
Actually I want to remove /web from the site URL. Website should be point to /public_html/web so that drupal index.php will be executed. Currently its pointing to /public_html only.
And if I change the document root to /public_html/web the site doesnt works as expected.
Thanks,
Setting DocumentRoot properly to /public_html/web should work as
expect. Provided you correct alterations to .htaccess to make it work when not set properly.
You could try to remove the redirect (r=301) in the example provided. The redirect causes the change in url communicated to browser. Without the redirect it only changes the path for the filesystem.
CPanel should allow to set DocumentRoot for your domain
However, some providers don't allow that. In that case I suggest to create a subdomain, where you can set the DocumentRoot. On your main domain you can redirect to the subdomain (index.html or .htaccess).
This makes your site available through your subdomain rather then domain. The DocumentRoot for your domain is no longer relevant as your site is made available through the subdomain, whose DocumentRoot points correctly to the web folder.
Use This:
We have just used the following code on one of our project running on a NameCheap shared host. Create a ".htaccess file inside your "public_html" directory, and paste the code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /web/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ web/index.php [L]