简体   繁体   English

如何在不转到主页的情况下重定向www?

[英]How can I redirect www without moving to the homepage?

Well I'm using this code to redirect the domain and ip: 好吧,我正在使用此代码重定向域和ip:

RewriteEngine On

rewritecond %{http_host} ^www.lucrebem.com.br [nc]
rewriterule ^(.*)$ http://lucrebem.com.br/$1 [r=301,nc]
RewriteRule ^(.*)['"$] /$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^216\.245\.194\.194
RewriteRule (.*) http://lucrebem.com.br/$1 [R=301,L]

What it does is removing the www from the url, but the problem is, if an user hits www.mysite.com/thecategory/thearticle , he won't be redirected to mysite.com/thecategory/thearticle , he will be redirected to mysite.com/index.php 它的作用是从网址中删除www,但是问题是,如果用户点击www.mysite.com/thecategory/thearticle ,则不会将其重定向到mysite.com/thecategory/thearticle ,他将被重定向至mysite.com/index.php

That's not what I'm trying to achieve and I believe this is affecting my rankings. 那不是我想要达到的目标,我相信这会影响我的排名。

Yeah this if of couse bad for your ranking. 是的,如果这对您的排名不利。 I do this as the following. 我这样做如下。

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Looks like you tried the same. 看起来您尝试过相同的方法。 Maybe you can remove ne [nc] breakets in line 2. 也许您可以在第2行中删除ne [nc]个breaket。
Another possbile reason could be that you got antoher redirecting Condition. 另一个可能的原因可能是您有另一个重定向条件。 But normally this should work fine. 但是通常这应该可以正常工作。

Greats, Traxstar 伟人,Traxstar

Here you go Buddy, this should remove the www and redirect it to domain + slugs: 在这里,您是好友,这应该删除www并将其重定向到domain + slugs:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

I would do it this way and you can combine you rules into one instead of separate rules. 我会这样做,您可以将规则组合成一个规则,而不是单独的规则。

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.lucrebem\.com\.br [NC,OR]
RewriteCond %{HTTP_HOST} ^216\.245\.194\.194
RewriteRule ^ http://lucrebem.com.br%{REQUEST_URI} [R=301,L]
<VirtualHost *:80>
    ServerName www.example.com
    Redirect permanent / http://example.com/
</VirtualHost>

or 要么

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Here is how I fixed it: 这是我的解决方法:

### Makes www Redirect to non-www without redirecting to index page
RewriteCond %{HTTP_HOST} ^www\.lucrebem\.com\.br
RewriteRule (.*) http://lucrebem.com.br/$1 [R=301,L]

And here is a Bonus for people who wants to redirect the Ip too: 对于那些也想重定向IP的人来说,这是一个奖励:

#Redirects IP, working fine, don't change anything below
RewriteCond %{HTTP_HOST} ^216\.245\.194\.194
RewriteRule (.*) http://lucrebem.com.br/$1 [R=301,L]

:) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM