301 会转到 ServerName 域

问题描述 投票:0回答:3

我有以下虚拟主机配置:

<VirtualHost *:80>
  ServerName www.something.com
  ServerAlias something1.com
  Include conf/vhost/www.something.com-rewrites.conf
</VirtualHost>

在 www.something.com-rewrites.conf 文件下:

RewriteRule ^/apps/(.*)$ / [R=301,L,E=cache_redirect:1]

如果有对

something1.com/apps/
的请求,我会看到正在发生重定向,但 URL 已更改为
www.something.com

我不明白这种奇怪的行为,他们还有其他方法可以阻止这种行为吗?

apache http-redirect vhosts
3个回答
0
投票

听起来您的 UseCanonicalName 有一个非默认值,或者您的客户端是 HTTP/1.0 并且不发送 Host: 标头。


0
投票

如果您的网站正在运行 WordPress 之类的 CMS,它将使用安装的域作为主域,并且无论您的 ServerAlias 和 ServerMain 设置如何,都会重定向到该主域。


0
投票

将虚拟主机的 UseCanonicalName 值设置为 Yes/On - 这将使用 mod_dir 生成的 301 中的 ServerName 值。 添加

origin.
作为服务器别名

https://httpd.apache.org/docs/current/mod/core.html#usecanonicalname

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.