【问题标题】:htaccess with wildcard SSL带有通配符 SSL 的 htaccess
【发布时间】:2012-04-17 06:58:05
【问题描述】:

我们有一个通配符 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

但无法让它工作。

有什么建议吗? 谢谢。

【问题讨论】:

  • 提示:mod_rewrite 可能会这样做。这确实属于服务器故障,因为它不是编程问题。
  • 好的,谢谢。我去那边看看。

标签: .htaccess ssl wildcard


【解决方案1】:

您不希望重写规则中的 [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”未找到。

【讨论】:

    猜你喜欢
    • 2014-04-01
    • 1970-01-01
    • 2013-02-16
    • 1970-01-01
    • 2014-02-28
    • 2015-03-06
    • 1970-01-01
    • 2014-05-10
    • 2021-12-14
    相关资源
    最近更新 更多