如何使用.htaccess映射不同的URL

如何使用.htaccess映射不同的URL,.htaccess,url,https,dns,mapping,.htaccess,Url,Https,Dns,Mapping,我需要我的所有域都有https证书,但当我创建.htaccess文件时,网站并没有关闭 故事是这样的: 我有一个RubyonRails网站,我们叫它:web1.com.br 我也有域名:web1.com、web2.com.br和web2.com 我进行了DNS映射,因此每当人们键入这3个域时,他们都会转到我在web1.com.br上的原始主机(并且不会更改用户的url),而且效果很好 但是当有人键入其他3个域时,我没有https证书。只有在我的原始网站web1.com.br上,我才有let's

我需要我的所有域都有https证书,但当我创建.htaccess文件时,网站并没有关闭

故事是这样的: 我有一个RubyonRails网站,我们叫它:web1.com.br

我也有域名:web1.com、web2.com.br和web2.com

我进行了DNS映射,因此每当人们键入这3个域时,他们都会转到我在web1.com.br上的原始主机(并且不会更改用户的url),而且效果很好

但是当有人键入其他3个域时,我没有https证书。只有在我的原始网站web1.com.br上,我才有let's encrypt证书

我向主机提供商寻求帮助,他们让我在www文件夹中添加一个.htaccess文件,但我可能做错了什么

RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.com.br.
RewriteRule ^ http://www.web1.com.br%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^web1\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.web1\.com$
RewriteRule ^$ http\:\/\/www\.web1\.com\.br\/ [R=301,L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.com.br.
RewriteRule ^ http://www.web1.com.br%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^web2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.web2\.com$
RewriteRule ^$ http\:\/\/www\.web1\.com\.br\/ [R=301,L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.com.br.
RewriteRule ^ http://www.web1.com.br%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^web2\.com\.br$ [OR]
RewriteCond %{HTTP_HOST} ^www\.web2\.com\.br$
RewriteRule ^$ http\:\/\/www\.web1\.com\.br\/ [R=301,L]
我创建了.htaccess文件,我的网站(在所有域上)关闭,给出了500个响应:

"The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at web@web1.com.br to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request."
我删除了文件,网站又重新上线了

正如你可能知道的,我是个彻头彻尾的笨蛋,但找不到人帮我。我不知道我是不是做错了.htaccess,还是我的主机支持给了我错误的信息


谢谢

在.htaccess文件中检查此规则,将所有内容重定向到


很抱歉,如果您操作不同的主机(主机名,有时也称为“域”或“子域”),那么您需要不同的证书。这是没有办法的。任何正常浏览器都不会接受与请求的主机名不匹配的证书。
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?web1\.com [NC]
RewriteRule (.*) https://web1.com.br/ [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?web2\.com [NC]
RewriteRule (.*) https://web1.com.br/ [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?web2\.com\.br [NC]
RewriteRule (.*) https://web1.com.br/ [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.web1\.com\.br [NC]
RewriteRule (.*) https://web1.com.br/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^web1\.com\.br [NC]
RewriteRule (.*) https://web1.com.br/$1 [R=301,L]