DEV Community

Mahmoud Sayed
Mahmoud Sayed

Posted on

1

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

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay