HTTPS 中的 Apache 重定向

标签 apache redirect ssl

我有一个 Apache 服务器 ( https://mysite.com/sub/en/ )。它在端口 443 和 VirtualHost 标记中使用 SSL 设置:

<VirtualHost _default_:443>
Redirect permanent /sub https://mysite.com/sub/en/
...
</VirtualHost>

基本上,当用户访问网站时,我希望他们被强制转到“/en”子目录。但是,如果您尝试访问 <a href="https://mysite.com/sub" rel="noreferrer noopener nofollow">https://mysite.com/sub</a> ,它不会将您重定向到子“/en”目录。

我真的不知道发生了什么。我的非 SSL 虚拟主机标签中确实有类似的设置:

<VirtualHost *:80>
Redirect permanent / https://mysite.com/sub/en/
Redirect permanent /sub https://mysite.com/sub/en
</VirtualHost>

这些规则工作正常。因此,如果用户尝试 <a href="http://mysite.com/sub" rel="noreferrer noopener nofollow">http://mysite.com/sub</a> ,它将它们转发到 SSL 版本,以及我想要的“/en”子目录。但是,如果您尝试使用 SSL 版本:<a href="https://mysite.com/sub" rel="noreferrer noopener nofollow">https://mysite.com/sub</a> , 转发失败。

我的配置有误吗?我没有使用正确的重定向或重写规则吗?

最佳答案

为了让这个按照我想要的方式工作,我最终使用了 RewriteRule:

RewriteRule ^/sub$ https://mysite.com/sub/en/

这似乎已经成功了。

关于HTTPS 中的 Apache 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14775035/

相关文章:

php - 重定向回 Laravel 中的特定选项卡 Pane

r - 如何解决此 RCurl 错误 : "SSL certificate problem: certificate has expired"?

php - 在 Linux 上使用 mod_xsendfile 使用 PHP 下载大文件

Apache:操作指令未激活 CGI 脚本

ruby-on-rails - 目录列表显示而不是 Rails App - Passenger Apache CentOS 6

ssl - 2 路 SSL/TLS 配置

ssl - 使用 MVC 通配符证书在 Azure 上托管许多 SSL 站点

java - 处理一个节点(4节点集群)ElasticSearch的客户端http通信时捕获到异常

asp.net - 返回新的RedirectResult()与返回Redirect()

git - git 命令的输出未完全重定向到文件