Htaccess将WWW重定向到非WWW是无情地从谷歌带来缓存副本


htaccess redirecting www to non www is relentlessly bringing cached copy from google?

我有一个非www设置域X.com.bd。当输入www.X.com.bd它给出了一个net::ERR_NAME_NOT_RESOLVED错误,并带来缓存复制建议页面从谷歌。我写了一个。htaccess规则

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

这是我的整个。htaccess片段:

  <IfModule mod_rewrite.c>
   # Turn on URL rewriting
   RewriteEngine On
   RewriteBase /
   RewriteCond %{HTTP_HOST} ^www'.(.+)$ [NC]
   RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
   # Protect application and system files from being viewed when the index.php is missing
   RewriteCond $1 ^(application|system|private|logs)
   # Rewrite to index.php/access_denied/URL
   RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
   # Allow these directories and files to be displayed directly:
   RewriteCond $1  ^(index'.php|robots'.txt|favicon'.ico|public|assets|resources|css|js|images|_assets|img)
  # No rewriting
   RewriteRule ^(.*)$ - [PT,L]
  # Rewrite to index.php/URL
  RewriteRule ^(.*)$ index.php/$1 [PT,L] 
  </IfModule> 

现在我只需要将www.X.com.bd重定向到X.com.bd

感谢您的帮助。

这不是一个htaccess问题(它甚至与apache无关)。net::ERR_NAME_NOT_RESOLVED表示无法对www.X.com.bd进行DNS解析。您需要将www.X.com.bd添加到x.com.bd的DNS区域。你的域名注册商/网站主机很可能有一个控制面板,你可以做到这一点。否则,他们的支持人员应该能够帮助您解决这个问题。

你应该添加一个CNAME或a记录(和/或AAAA,如果你的服务器使用IPv6),如:

www.X.com.bd. IN CNAME X.com.bd

或:

www.X.com.bd. IN A 127.0.0.1 // But then with your actual server's IPv4 address
www.X.com.bd. IN AAAA ::1 // Replace with your server's IPv6 address