在 .htaccess 中,重定向除一个之外的所有域 [英] In .htaccess, redirect all domains except one

查看:30
本文介绍了在 .htaccess 中,重定向除一个之外的所有域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器上有多个域.我想将它们全部重定向到一个(example.net).

I have multiple domains on my server. I want to redirect all of them to one (example.net).

我的.htaccess:

My .htaccess:

RewriteEngine on 
RewriteRule ^(.*)$ http://www.example.net/$1 [R=301,L]

我将服务器上的所有 URL 重定向到一个主域,但该域也在重定向到自身.因此 www.example.net 返回 301 Moved Permanently 并重定向回自身.有人告诉我这对 SEO 不利.我该如何解决这个问题?

I’m redirecting all URLs on my server to one main domain, but that domain is also redirecting to itself. So www.example.net returns 301 Moved Permanently and redirects back to itself. I’m told that this isn’t good for SEO. How could I fix this?

推荐答案

你需要添加一个 Rewritecond 以防止它在你已经在你想要的域中时重定向.如果你用谷歌搜索,网上有很多例子,或者查看 RewriteCond 部分Apache 的 mod_rewrite 文档.

You need to add a Rewritecond to prevent it from redirecting when you’re already on the domain that you want. There are loads of examples online if you google it, or see the RewriteCond section of Apache’s mod_rewrite documentation.

您正在寻找的内容类似于:

What you’re looking for is something like:

RewriteEngine on 
Rewritecond %{HTTP_HOST} !^www.example.net
RewriteRule ^(.*)$ http://www.example.net/$1 [R=301,L]

这篇关于在 .htaccess 中,重定向除一个之外的所有域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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