.htaccess - htaccess 与通配符 SSL

标签 .htaccess ssl wildcard

我们有一个通配符 SSL 证书,它应该可以在给定域的任何子域上工作。

所以在这个服务器中我们有这个文件结构:

/home/DOMAIN/public_html/subdomainx
/home/DOMAIN/public_html/subdomainy
等等……

现在,证书已安装,但是当您通过 https 访问任何子域时(例如:hxxps://subdomainx.domain.com)它指向

/home/DOMAIN/public_html/index.php

当您通过 https 访问子域时,我们需要它
hxxps://subdomainx.domain.com

它指向与 http 等效的同一目录: /home/DOMAIN/public_html/subdomainx

我们的提供者告诉我们这是不可能的,当前的行为是正确的,我们应该做一些 htaccess 来实现这一点。

我已经尝试了一些东西,包括这个解决方案,这似乎是我需要的:Advice on Configuring .HTaccess file to Redirect HTTP Subdomain to HTTPS Equivalent

但无法让它工作。

有什么建议吗? 谢谢。

最佳答案

您不希望在重写规则中使用 [R] 标志,或者在目标中使用主机名。您想要重写 URI,以便在其前面加上“subdomainx”。类似的东西:

RewriteEngine On

# We don't want the main domain or www
RewriteCond %{HTTP_HOST} ^((?!www).*)\.domain.com$ [NC]

# Make sure that if we rewrite, the destination actually exists (to prevent loops and properly return 404's)
RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_URI} -d

# rewrite
RewriteRule ^(.*)$ /%1/$1 [L]

请注意,%{DOCUMENT_ROOT}/%1%{REQUEST_URI} 检查必须以便在不泄露信息的情况下返回正确的 404。当您请求 http://test.domain.com/badfile.html 时,这就是如此,404 消息表示“/badfile.html”未找到,而不是“/test/badfile.html”未找到。

关于.htaccess - htaccess 与通配符 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9996368/

相关文章:

php - 使用 PHP 到动态阿拉伯语类别 URL 的 SEO 友好 URL

ruby-on-rails - 如何使用 Puma 配置 Rails 以使用 SSL?

php - stream_socket_client 通过 http 代理

python - 通过匹配整数的第 n 位数字来返回 Pandas 数据帧中的行?

java - 替换字符串中的值

php - 使用 htaccess 获取值(value)和重定向

apache - .htaccess mod_rewrite,在某些情况下删除第一段(当它是国家/地区代码时)

apache - 如何创建 .htaccess 来显示 SVG?

redirect - 使用 ssl 的 nginx 重定向循环

javascript - 字符串相等性测试中的通配符