【问题标题】:htaccess for www force on Domain + Subdomain and only SSL for Subdomainhtaccess 用于域 + 子域上的 www 强制,并且仅用于子域的 SSL
【发布时间】:2015-05-07 12:02:44
【问题描述】:

我有一个网站,但 .htaccess 确实存在一些问题... 我尝试了 6 个小时来解决它.. 我希望有人可以帮助我。我刚刚添加了一个子域,包括。 ssl ...

问题: 1.)对于需要以下的主域(www.domain.com)

  • example.com 应转换为 www.example.com
  • 将 www.example.com/index.html 重写为 www.example.com
  • 没有 SSL --> http

主域的 html 页面位于根文件夹中

2.) 对于我的子域 xy.domain.com,我需要:

  • 还有 xy.domain.com --> www.xy.domain.com
  • 强制 SSL 和 https

子域的内容位于 root/folder2... 子域重定向到 /folder2

我希望有人有解决方案:) 非常感谢!

最近的 htaccess 是这样的

ErrorDocument 404 /page-404.html
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,QSA,L]
RewriteRule ^index\.(html?|php)$ http://%{HTTP_HOST}/ [R=301,QSA,L]

【问题讨论】:

  • 你能分享一下你的配置吗?
  • @xlm 确定我刚刚在我的问题中添加了它 - 抱歉!我已经通过搜索类似的主题尝试了很多不同的解决方案,但我找不到合适的解决方案 - 我远不擅长编程:)

标签: .htaccess mod-rewrite ssl


【解决方案1】:

所以经过一些工作,我来到了这一点......它有效但并不完美:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^index\.(html?|php)$ http://%{HTTP_HOST}/ [R=301,QSA,L]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^www\.(sub\.domain\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

如果有人能告诉我,我该如何实施包含以下重写的规则: http://www.domain.com/folder1https://www.sub.domain.com

我无法弄清楚如何强制使用 www。到副...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-12
    • 1970-01-01
    • 2014-03-31
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    • 2018-12-22
    • 1970-01-01
    相关资源
    最近更新 更多