301重定向,除了子域整个网站

编程入门 行业动态 更新时间:2024-10-16 00:23:35
本文介绍了301重定向,除了子域整个网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^.* %{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 RewriteCond %{HTTP_HOST} !=blog.example RewriteCond %{HTTPS} !=on RewriteRule ^.* %{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\$ [NC] RewriteCond %{HTTPS} !=on RewriteRule ^ %{HTTP_HOST}%{REQUEST_URI} [R=301,L]

更多推荐

301重定向,除了子域整个网站

本文发布于:2023-10-31 13:53:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546281.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   网站

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!