添加www的.htaccess。仅在主域前面,保持子域不变

时间:2021-12-10 11:18:21

Let's say I have a domain called 'example.com'. I need a htaccess file that adds 'www.' in front of the main domain 'example.com' when the users types the main domain name without 'www.'. I also want to create lots of subdomains, let's say 'sub1.example.com', 'sub2.example.com' and 'sub3.example.com'. I want all subdomains that I create to be left unchanged, whenever the user enters them with 'www.' or not.

假设我有一个名为'example.com'的域名。我需要一个添加'www。'的htaccess文件。当用户键入没有“www。”的主域名时,在主域“example.com”前面。我还想创建许多子域名,比如说“sub1.example.com”,“sub2.example.com”和“sub3.example.com”。我希望每当用户使用“www”输入时,我创建的所有子域都保持不变。或不。

1 个解决方案

#1


I just stumbled upon the answer...

我只是偶然发现了答案......

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#1


I just stumbled upon the answer...

我只是偶然发现了答案......

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]