在.htaccess,重定向所有领域除一人外 [英] In .htaccess, redirect all domains except one

查看:154
本文介绍了在.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]

我在我的重定向服务器到一个主域名的所有网址,但该领域也重定向到自身。所以www.example.net返回 301永久移动和重定向回自己。有人告诉我,这是不利于搜索引擎优化。我怎么能解决这个问题?

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 的以prevent它。如果你google一下,或者看到Apache的mod_rewrite文档的的RewriteCond节

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天全站免登陆