如何为 Drupal 8 正确设置 Apache 虚拟主机

如何为 Drupal 8 正确设置 Apache 虚拟主机

我在这个路径安装了Drupal网站:

/var/www/html/testdrupal.localhost/public_html/drupal/web

下面我展示虚拟主机配置文件testdrupal.localhost:

<Directory /var/www/html/testdrupal.localhost>
    Require all granted
</Directory>
<VirtualHost *:80>
    ServerName testdrupal.localhost
    ServerAlias www.testdrupal.localhost
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/testdrupal.localhost/public_html/drupal/web

    ErrorLog /var/www/html/testdrupal.localhost/logs/error.log
    CustomLog /var/www/html/testdrupal.localhost/logs/access.log combined

</VirtualHost>

当我访问 URL www.testdrupal.localhost 时,我可以正确地看到 Drupal 的起始页,但是当我单击登录链接时,出现 404 错误。

浏览器地址栏上显示的URL是:

http://www.testdrupal.localhost/drupal/web/user/login

我还验证了:

答案1

可能有点旧,你可能已经解决了这个问题,但我会发布答案,以便它可能会帮助其他人。

 <VirtualHost *:80>
  DocumentRoot /var/www/html/my_project/docroot
  ServerName ${alias}
  ServerAlias ${alias}

  <Directory /var/www/html/my_project/docroot>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

${alias} = is the name you wrote in the hosts file, next to the IP address of localhost

答案2

我也遇到了同样的问题。经过几天的反复尝试,我找到了解决方案。

index.php我必须更改文件.htaccess中提到的位置Drupal 的建议

旧设置:

  # Pass all requests not referring directly to files in the filesystem to
  # index.php.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L]

新设置:

  # Pass all requests not referring directly to files in the filesystem to
  # index.php.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ /drupal/index.php [L]

相关内容