drwo2014 2014-05-28 15:34
浏览 114
已采纳

htaccess将www重定向到非www是无情地从谷歌带来缓存副本?

I have a non www setup for a domain X.com.bd . when typed www.X.com.bd it gives a net::ERR_NAME_NOT_RESOLVED error and brings cached copy suggestion page from google. I've written an .htaccess rule as

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

And here is my whole .htaccess snippet :

  <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> 

Now all I need is to redirect www.X.com.bd to X.com.bd

Any help is appreciated and thanks in advance.

  • 写回答

1条回答 默认 最新

  • douji2520 2014-05-28 15:36
    关注

    This is not a htaccess problem (it's not even apache related).net::ERR_NAME_NOT_RESOLVED means that there is no DNS resolution possible for www.X.com.bd. You will need to add www.X.com.bd to the DNS zone of x.com.bd. Your domain registrar/webhost will most likely have a control panel where you can do this. Otherwise their support staff should be able to help you with this.

    You should add a CNAME or A record (and/or AAAA if your server uses IPv6), like:

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

    Or:

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用