在 .htaccess 中,重定向除一个之外的所有域

编程入门 行业动态 更新时间:2024-10-27 00:25:46
本文介绍了在 .htaccess 中,重定向除一个之外的所有域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

我的.htaccess:

My .htaccess:

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

我将服务器上的所有 URL 重定向到一个主域,但该域也在重定向到自身.因此 www.example 返回 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 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 RewriteRule ^(.*)$ www.example/$1 [R=301,L]

更多推荐

在 .htaccess 中,重定向除一个之外的所有域

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

发布评论

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

>www.elefans.com

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