1

I have a site using Drupal 8.5 I installed with Composer.
When users want to visit the site, they'd normally need to add /web after the domain to access it. I have a cpanel redirect that redirects users from domain abc.com to abc.com/web, so they don't have to add /web.
This solution is still a bit silly because the visitors still see the abc.com/web while I really want it to look like a regular website domain, domain.com.

I'm not allowed to use virtual hosts, but I am allowed to use htacces or symlinks. How do I "redirect" visitors from domain localhost/temp-project to localhost/temp-project/web/index.php without having /web in the URL?

--Update 2-- I've tried to add a .htaccess snippet (from GitHub) in my root (localhost/temp-project) to point to /web and browsed to localhost/temp-project:

#Redirect to www location with subdirectory
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} localhost/temp-project [NC]
RewriteRule ^(.*)$ /web/index.php[R=301,NC]

This just doesn't do anything, what's going wrong here?

1

5 Answers 5

4

You should have your host point directly to the "web" directory instead of your project root. I've run into this issue on webfaction hosting and my solution (actually my co-worker's) was to have 2 "apps." The first app is not web accessible and this is where my drupal-composer/drupal-project's root is. Then I create a second app that is web accessible, e.g. domain.com and is a symlink to the first app's /web directory. Maybe you can use this same approach.

2
  • Hi Sonfd, what do you mean exactly with the term "app"?
    – Ducky
    Commented Apr 21, 2018 at 21:56
  • I'm not sure what would be the equivalent on your hosting provider. But basically on webfaction an app could be a directory where you placed static html, or a php app, or a python app, or a symlink, etc. Maybe try the solution [here] (drupal.stackexchange.com/questions/241761/…).
    – sonfd
    Commented Apr 21, 2018 at 22:07
3

If using cPanel:

  1. Go to Domains > Domains.
  2. Click "Manage" for the domain you want
  3. Edit the path to the "New Document Root".
0

If you can't change the project root, then I'd suggest either doing a Rewrite directive within .htaccess or just making an alias on Drupal (or setting the homepage to be /web).

-2

I have a very simple way I solve this issue. Instead of reconfiguring server to set new document root or writing rewrites, I think it is so far easier to make a 'modified install'. It is simple, takes a few minutes to modify your composer.json and complete your installation, and for the life of the website, you don't have to tamper with any server settings nor .htaccess nor settings.php nor any of such. It very easily saves tons of headache getting round the 'web/' folder issue, it neatly avoids it and gets you to set whatever you want as your web-root.

Read more in this my answer, How to remove subdir from base URL after installing site with Composer on a shared host?

-2

Step 1. You have to install Drupal using this command composer create-project --no-install drupal/recommended-project my_site_name_dir with the help of composer.

Step 2. You have to make some changes in the composer.json file as per the code listed below and you have to save file.

    "extra": {
    "drupal-scaffold": {
        "locations": {
            "web-root": "./"
        }
    },
    "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"
        ]
    },
      

Step 3. After that you have to enter in my_site_name_dir directory of the project and run this command composer install in composer.

Step 4 Your code is ready you need to setup your project accordingly.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Aug 29, 2022 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.