.htaccess - htaccess for www force on Domain + Subdomain and only SSL for Subdomain

标签 .htaccess mod-rewrite ssl

我有一个网站,但我在使用 .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]

最佳答案

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

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。到子...

关于.htaccess - htaccess for www force on Domain + Subdomain and only SSL for Subdomain,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28889364/

相关文章:

apache - 将 .php 重定向到无扩展名并创建没有 .php 的 url

regex - 使用 .htaccess 重定向到动态相对路径?

.htaccess - Htaccess 从末尾的数字重定向

php - .htaccess url-rewrite 如果文件不存在 - 如何处理 favicon.ico?

页面为 SSL 时的 Apache 重定向

asp.net-mvc - 如果使用协议(protocol) "https"的安全页面,则不会从 CDN URL 加载 js 和 css

.htaccess - htaccess - 将所有非 www 流量重定向到 www

regex - 使用正则表达式重写规则以添加正斜杠

python - 在 Python 中实现传输层安全 - 简单的邮件客户端

android - Android 认可哪种 SSL 证书?