如何在域指向后使用 htaccess 在 drupal 8 安装中从 URL 跳过 Web 目录?
How to skip web directory from URL in drupal 8 installation using htaccess after domain pointing?
我安装了我的 drupal 网站并使用 ip 地址添加了初始配置和页面,例如:http://111.22.33.88/web
我的安装目录如下(我只是加了基本的文件才知道结构)
public_html/
vendors/
web/
core/
sites/
modules/
themes/
.htaccess
index.php
一切正常,但在将我的 IP 地址指向我的域后 www.mysite.com。仅当我在路径中添加 web 子文件夹时它才能正常工作,即 www.mysite.com/web
我不需要 url 中的 web 文件夹。我找到了一个使用 .htaccess 文件的解决方案,代码如下
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ web/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/web%{REQUEST_URI} -f
RewriteRule .* web/[=12=] [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* web/index.php?q=[=12=] [QSA]
我通过在 /public_html/.htaccess
中创建一个新的 htaccess 文件添加了上述代码
站点和管理员链接有效,但仍然存在一些问题,即以管理员身份登录后,www.mysite。com/user/login,站点已登录但显示如下错误的白页
"Redirects to external URLs are not allowed by default, use \Drupal\Core\Routing\TrustedRedirectResponse for it."
谁能帮忙解决这个问题,我想我在新创建的 .htaccess 文件中遗漏了一些东西或一些额外的设置来消除 web 目录
您可以通过在 settings.php
中添加以下内容来消除该问题
if (isset($GLOBALS['request']) and
'/web/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME')) {
$GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');
}
我遇到了同样的问题,但我在没有代码的情况下采用了不同的方法。我的虚拟主机 (inmotion) 允许您提供根文件夹,在我的例子中,我试图将域名指向一个子文件夹。所以我将域名指向 /public_html/subfolder/web 而不是 /public_html/subfolder。它奏效了。
我安装了我的 drupal 网站并使用 ip 地址添加了初始配置和页面,例如:http://111.22.33.88/web 我的安装目录如下(我只是加了基本的文件才知道结构)
public_html/
vendors/
web/
core/
sites/
modules/
themes/
.htaccess
index.php
一切正常,但在将我的 IP 地址指向我的域后 www.mysite.com。仅当我在路径中添加 web 子文件夹时它才能正常工作,即 www.mysite.com/web
我不需要 url 中的 web 文件夹。我找到了一个使用 .htaccess 文件的解决方案,代码如下
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ web/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/web%{REQUEST_URI} -f
RewriteRule .* web/[=12=] [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* web/index.php?q=[=12=] [QSA]
我通过在 /public_html/.htaccess
中创建一个新的 htaccess 文件添加了上述代码站点和管理员链接有效,但仍然存在一些问题,即以管理员身份登录后,www.mysite。com/user/login,站点已登录但显示如下错误的白页 "Redirects to external URLs are not allowed by default, use \Drupal\Core\Routing\TrustedRedirectResponse for it."
谁能帮忙解决这个问题,我想我在新创建的 .htaccess 文件中遗漏了一些东西或一些额外的设置来消除 web 目录
您可以通过在 settings.php
中添加以下内容来消除该问题if (isset($GLOBALS['request']) and
'/web/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME')) {
$GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');
}
我遇到了同样的问题,但我在没有代码的情况下采用了不同的方法。我的虚拟主机 (inmotion) 允许您提供根文件夹,在我的例子中,我试图将域名指向一个子文件夹。所以我将域名指向 /public_html/subfolder/web 而不是 /public_html/subfolder。它奏效了。