我有一个网站,但我在使用 .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/folder1
到 https://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/