![](/img/trans.png)
[英]redirecting https://domain.com to https://www.domain.com
[英]redirect http://www.domain.com to https://domain.com
我有以下apache虛擬主機:
NameVirtualHost *:443
<VirtualHost *:80>
<Directory /home/www/htdocs/domain.tl/html/>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.tl$ [NC]
RewriteRule ^(.*)$ http://fr.domain.tl/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName domain.tl
ServerAlias www.domain.tl fr.domain.tl en.domain.tl files.domain.tl
DocumentRoot /home/www/htdocs/domain.tl/html/
...
<Directory /home/www/htdocs/domain.tl/html/>
Options -Indexes FollowSymLinks
AllowOverride All
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.tl$ [NC]
RewriteRule ^(.*)$ https://fr.domain.tl/$1 [L,R=301]
</Directory>
</VirtualHost>
我想將http://www.domain.tl或http://domain.tl重定向到https://fr.domain.tl
實際上,使用此虛擬主機,http到https的重定向是正確的,但子域不會更改
嘗試更改這些行:
RewriteCond %{HTTP_HOST} ^domain.tl$ [NC]
RewriteRule ^(.*)$ http://fr.domain.tl/$1 [L,R=301]
至
RewriteCond %{HTTP_HOST} ^(?:www\.)domain.tl$ [NC]
RewriteRule ^(.*)$ https://fr.domain.tl/$1 [L,R=301]
這樣它也匹配“www.domain.tl”並在兩個虛擬主機中重定向到https:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.