![](/img/trans.png)
[英]How can I redirect a user to a www domain in PHP without the http?
[英]How can I redirect www without moving to the homepage?
好吧,我正在使用此代碼重定向域和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]
它的作用是從網址中刪除www,但是問題是,如果用戶點擊www.mysite.com/thecategory/thearticle
,則不會將其重定向到mysite.com/thecategory/thearticle
,他將被重定向至mysite.com/index.php
那不是我想要達到的目標,我相信這會影響我的排名。
是的,如果這對您的排名不利。 我這樣做如下。
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
看起來您嘗試過相同的方法。 也許您可以在第2行中刪除ne [nc]個breaket。
另一個可能的原因可能是您有另一個重定向條件。 但是通常這應該可以正常工作。
偉人,Traxstar
在這里,您是好友,這應該刪除www
並將其重定向到domain + slugs:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
我會這樣做,您可以將規則組合成一個規則,而不是單獨的規則。
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>
要么
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
這是我的解決方法:
### 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]
對於那些也想重定向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.