gpt4 book ai didi

linux - Apache2,将 blank.example.com 重定向到 example.com/blank/blank

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:49:10 26 4
gpt4 key购买 nike

我对此重定向有疑问。我试过使用 RewriteRule 和 RewriteCond 的 .htaccess 方法,以及 VirtualDirectory 方法。这是我为 VirtualHost 所做的尝试:

<VirtualHost *:80>
ServerName blank.example.com
Redirect permanent / "http://example.com/blank/blank"

</VirtualHost>



<VirtualHost *:80>

ServerName example.com

ServerAdmin webmaster@localhost
DocumentRoot /the/doc/root

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

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

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

这是 .htaccess 的:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^blank.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/blank/blank [R=301,L]

我不确定是否需要它,但是 blank.example.com 也指向/etc/hosts 中的 localhost

有什么关于我遗漏的提示吗?

最佳答案

这里有一些事情。

如果您只想拥有一个具有自己的文档根目录的子域,那么您的虚拟主机需要如下所示。那么就不需要重定向了。

<VirtualHost *:80>
ServerName blank.example.com
DocumentRoot /path/to/blank/blank
<Directory /path/to/blank/blank>
#enable .htaccess for this subdomain
AllowOverride All
</Directory>
</VirtualHost>

如果您真的想将您的子域重定向到主域。

然后删除第一个 vhost。根本不需要。

 #This virtualhost is not needed
<VirtualHost *:80>
ServerName blank.example.com
Redirect permanent / "http://example.com/blank/blank"
</VirtualHost>

然后在您的主 VirtualHost 上添加一个服务器别名,如下所示

ServerName example.com
ServerAlias blank.example.com
ServerAdmin webmaster@localhost
DocumentRoot /the/doc/root

<Directory /the/doc/root>
#enable .htaccess for this main domain
AllowOverride All
</Directory>

然后是你的 .htaccess 规则

RewriteEngine on
RewriteCond %{HTTP_HOST} ^blank\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/blank/blank/$1 [R=301,L]

所有配置文件更改后重新启动 Apache。

关于linux - Apache2,将 blank.example.com 重定向到 example.com/blank/blank,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33618895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com