301 重定向到具有 Multisite/Shared 托管的非 www ssl 版本
301 Redirect to non-www ssl Version with Multisite/Shared Hosting
我有一个与 Godaddy.com 共享的托管帐户,用于托管五个不同的网站(site1.com、site2.com ... site5.com)。我想在 / 目录中放置一个 .htaccess 文件,使所有五个不同的网站都重定向到每个网站的非 www 和 ssl 版本。
现在我的 .htaccess 文件中有以下内容:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.site1.com
RewriteRule (.*) https://site1.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.site2.com
RewriteRule (.*) https://site2.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.site3.com
RewriteRule (.*) https://site3.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.site4.com
RewriteRule (.*) https://site4.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.site5.com
RewriteRule (.*) https://site5.com/ [R=301,L]
站点的目录结构已设置,因此站点 1 的 index.html 位于 /public_html/index。html
另外四个站点的索引文件位于:
/public_html/[站点#]/index.html
[site#] (site2/ site3/ site4/ site5/)
有四个不同的目录
当我在浏览器中输入站点 2-4 的 URL 的 www 版本时,服务器会自动重定向到 https 版本的:
站点#.com/other_sites/site#.com
我希望每个网站都重定向到 ssl,即使访问者没有输入该网站的 www 版本。我知道我需要额外的 RewriteCond 和 RewriteRule,但不知道要使用什么代码。
我刚开始学习 RegEx 和服务器配置,如有任何帮助,我们将不胜感激。
您可以使用:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
我有一个与 Godaddy.com 共享的托管帐户,用于托管五个不同的网站(site1.com、site2.com ... site5.com)。我想在 / 目录中放置一个 .htaccess 文件,使所有五个不同的网站都重定向到每个网站的非 www 和 ssl 版本。
现在我的 .htaccess 文件中有以下内容:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.site1.com
RewriteRule (.*) https://site1.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.site2.com
RewriteRule (.*) https://site2.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.site3.com
RewriteRule (.*) https://site3.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.site4.com
RewriteRule (.*) https://site4.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.site5.com
RewriteRule (.*) https://site5.com/ [R=301,L]
站点的目录结构已设置,因此站点 1 的 index.html 位于 /public_html/index。html
另外四个站点的索引文件位于: /public_html/[站点#]/index.html [site#] (site2/ site3/ site4/ site5/)
有四个不同的目录当我在浏览器中输入站点 2-4 的 URL 的 www 版本时,服务器会自动重定向到 https 版本的:
站点#.com/other_sites/site#.com
我希望每个网站都重定向到 ssl,即使访问者没有输入该网站的 www 版本。我知道我需要额外的 RewriteCond 和 RewriteRule,但不知道要使用什么代码。
我刚开始学习 RegEx 和服务器配置,如有任何帮助,我们将不胜感激。
您可以使用:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]