htaccess的301第三级域名重定向 [英] htaccess 301 redirect from third level domain

查看:254
本文介绍了htaccess的301第三级域名重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,www.example.com 我有一个三级域名,start.example.com,会被重定向到

 的RewriteCond%{HTTP_HOST} ^ start.example \ .COM $ [NC]
重写规则^(。*)$的index.php开始= 1&安培; $ 1
 

但不知何故,包括谷歌的主要领域的第三个顶级域名中搜索页面, 例如:

  start.example.com/news/
 

所以我想301重定向所有这些链接到主域

  start.example.com/news/ => www.example.com/news/
 

但保持第一重定向正常工作。

我如何能做到这一点,帮助,好吗?

P.S。首先重定向仅用于统计,使用URL像

  start.example.com/?utm_source=whatever&utm_medium=start
 

解决方案

您可以尝试这条规则:

 的RewriteCond%{HTTP_HOST} ^开始\ .EXAMPLE \ .COM $ [NC]
?重写规则^([^ /] *)$的index.php开始= 1&安培; $ 1 [L,QSA]

的RewriteCond%{HTTP_HOST} ^开始\ .EXAMPLE \ .COM $ [NC]
重写规则^指数\ .PHP $ HTTP://www.example.com% {REQUEST_URI} [L,R = 301]
 

I have a website, www.example.com And I have a third level domain, start.example.com, which redirects to

RewriteCond %{HTTP_HOST} ^start.example\.com$ [NC]
RewriteRule ^(.*)$ index.php?start=1&$1

But somehow Google included pages of the main domain to the third level domain in search, for example

start.example.com/news/ 

So I'd like to redirect 301 all such links to the main domain

start.example.com/news/  =>  www.example.com/news/ 

but keep the first redirect working properly.

How can I do it, help, please?

P.S. First redirect is used for statistics only, with urls like

start.example.com/?utm_source=whatever&utm_medium=start 

解决方案

You can try these 2 rules:

RewriteCond %{HTTP_HOST} ^start\.example\.com$ [NC]
RewriteRule ^([^/.]*)$ index.php?start=1&$1 [L,QSA]

RewriteCond %{HTTP_HOST} ^start\.example\.com$ [NC]
RewriteRule !^index\.php$ http://www.example.com%{REQUEST_URI} [L,R=301]

这篇关于htaccess的301第三级域名重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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