DEV Community

Mahmoud Sayed
Mahmoud Sayed

Posted on

Remove /web from URL in Drupal

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 must 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 is the summary, which I learned:

1- Move all files and folders from web to root folder
2- Open composer.json remove /web and add ./

"drupal-scaffold": {
 "locations": {
    "web-root": "./"
 }
},
Enter fullscreen mode Exit fullscreen mode

3- Remove /web from composer.json in installer-paths

"installer-paths": {
  "core": [
    "type:drupal-core"
   ],
  "libraries/{$name}": [
   "type:drupal-library"
  ],
   "modules/contrib/{$name}": [
     "type:drupal-module"
   ],
   "profiles/contrib/{$name}": [
     "type:drupal-profile"
    ],
    "themes/contrib/{$name}": [
     "type:drupal-theme"
     ],
     "drush/Commands/contrib/{$name}": [
      "type:drupal-drush"
     ],
     "modules/custom/{$name}": [
       "type:drupal-custom-module"
     ],
     "profiles/custom/{$name}": [
       "type:drupal-custom-profile"
    ],
    "themes/custom/{$name}": [
       "type:drupal-custom-theme"
      ]
  },
Enter fullscreen mode Exit fullscreen mode

4- Open file autoload.php replace code with:

return require __DIR__ . '/vendor/autoload.php';
Enter fullscreen mode Exit fullscreen mode

5- Remove vendor and core folders and run this command:

$composer install
$drush cr
Enter fullscreen mode Exit fullscreen mode

If there is a better way than this, please let me know in the comments. Thanks

Top comments (0)