具有HTTPS的HTACCESS和具有端口的子域

时间:2018-11-27 19:42:05

标签: .htaccess

我花了几个小时来找到一个简单问题的答案,但我没有。在apache服务器上使用htaccess,我想要:

1-所有流量均为HTTPS

http://example.com >> https://example.com

(编辑)并且

2-到子域的所有流量都将重定向到特定端口

subdom.example.com >> subdom.example.com:1234

我创建了这个废话,但并非在所有情况下都有效

RewriteEngine On

RewriteCond %{SERVER_NAME} ^subdom.example.com$
RewriteCond %{SERVER_PORT} !^1234$
RewriteRule ^(.*)$ https://%{SERVER_NAME}:1234%{REQUEST_URI} [L,R=301]

# If not https, then force it
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301] 

最后,很高兴总是将example.com重定向到www.example.com

谢谢大家的支持

0 个答案:

没有答案