301重定向,除了子域整个网站 [英] 301 redirect for entire site except for subdomains

查看:98
本文介绍了301重定向,除了子域整个网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了网站范围301在我的.htaccess重定向如下:

I have setup a sitewide 301 redirect in my .htaccess as follows

RewriteEngine On 
RewriteCond %{HTTPS} !=on 
RewriteRule ^.* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 

不过,我想从被包括在这个重定向排除子域(支持博客)。所以,我想补充以下RewriteConditions

But I wanted to exclude subdomains (support, blog) from being included in this redirect. So I add the following RewriteConditions

RewriteEngine On 
RewriteCond %{HTTP_HOST} !=support.example.com
RewriteCond %{HTTP_HOST} !=blog.example.com
RewriteCond %{HTTPS} !=on 
RewriteRule ^.* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 

这工作完全正常。不过,我不知道是否有更好的方法,在短短1的RewriteCond声明(而不是为每个子域单独的RewriteCond)

This works totally fine. However I wonder if there is a better way to specify the exclusion for all subdomains (not WWW) in just 1 RewriteCond statement (instead of a separate RewriteCond for each subdomain)

我有几个子域,并计划增加一些。请问AP preciate的帮助。

I have a few more subdomains and plan to add some more. Would appreciate the help.

推荐答案

您可以使用此规则:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{HTTPS} !=on 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

这篇关于301重定向,除了子域整个网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆