BRAHMA TECHNOLAB

Remove /web part from a Composer based Drupal site

By default when you create your Drupal project using composer it will create project under /web directory.

When you’re using shared hosting for your Drupal website which points your domain to /public_html folder and you’re not allow to change that pointing directory

Now whenever your targeted audience will have to visit your website they have to open it like this http://example.com/web . and which is not a good user experience to add /web at the end of your url to view Home page of your website.

So, How can we serve our website from /public_html/web folder but no need to append /web in URL by your targeted audience?

Here are the summary, which I learned from this thread on Drupal.org

1. Open your settings.php file and add the following code:

if ( isset($GLOBALS['request']) && '/web/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME') ) {
    $GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');
}

2. Create a .htaccess file on the /public_html folder with:

<IfModule mod_rewrite.c>
RewriteEngine on
# Redirect to the subdirectory because that's where Drupal is installed
RewriteRule (.*) web/$1 [L]
</IfModule>

3. Update .htaccess under /public_html/web folder

Uncomment the line RewriteBase and set it to:


RewriteBase /web

4. Clear the cache and run update.php

Your site should work by browsing http://example.com now [ i.e. without the /web suffix ]. Your menu items may still have the /web part, but it will be gone after some hard refresh.

5. If you want to redirect http/https and www/non-www:

On the .htaccess file under /public_html/web, please add those lines between the <IfModule mod_rewrite.c> tag

This is to redirect non-https + www to https + non-www:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) https://example.com/$1 [L,R=301]

And this is to redirect non-https + non-www to https + www”

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L]

Please find more details on .htaccess made easy

LET’S DISCUSS YOUR PROJECT

10 responses to “Remove /web part from a Composer based Drupal site”

  1. This is really interesting, You’re a very skilled blogger. I’ve joined your feed and look forward to seeking more of your magnificent post. Also, I’ve shared your site in my social networks!

  2. Hey there! I just wish to give you a huge thumbs up
    for your great information you have got right here on this post.
    I am returning to your web site for more soon.

  3. Hi! I realize this is somewhat off-topic but I had to
    ask. Does building a well-established blog such as yours take a large amount of work?
    I am completely new to operating a blog however I do write in my
    journal every day. I’d like to start a blog
    so I can easily share my own experience and views online.

    Please let me know if you have any kind of suggestions or tips for new
    aspiring blog owners. Thankyou!

  4. Hello there I am so happy I found your web site, I really found you by error, while I was searching on Yahoo for something else,
    Regardless I am here now and would just like to say thanks for a fantastic post and a all round interesting blog (I also
    love the theme/design), I don’t have time to look over it all at
    the minute but I have bookmarked it and also added in your
    RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up
    the fantastic job.

Leave a Reply

Your email address will not be published. Required fields are marked *

Snehal

Typically replies within a day

Hello, Welcome to BRAHMA TECHNOLAB. Please click below button for chatting us through Skype.