Apache服务器301重定向去掉index.html和index.php尾巴

在做优化网站的时候,会考虑到网站整站的集权,通常市面上常见的帝国cms 织梦cms等都会自带首页index.html等文件,为了避免蜘蛛在爬行过程中权重的流失,导致重复收录首页页面,作为一枚站长,必须学会集中权重的策略,下面就为大家简单的介绍下一个集中权重的方式:

考虑到网站可以生成静态,首先,让网站优先访问 index.html

Apache服务器301重定向去掉index.html和index.php

之后考虑:去掉 .html 和 .php。

利用.htaccess

  1. 复制代码 
  2. <IfModule mod_rewrite.c> 
  3.  RewriteEngine on 
  4.  RewriteBase / 
  5.  RewriteCond %{REQUEST_FILENAME} !-d 
  6.  RewriteCond %{REQUEST_FILENAME} !-f 
  7.  RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L] 
  8. </IfModule> 

修改:

  1. <IfModule mod_rewrite.c> 
  2.  RewriteEngine on 
  3.  RewriteBase / 
  4.  RewriteCond %{HTTP_HOST} ^www.yn37wang.com$ [NC] 
  5.  RewriteCond %{REQUEST_URI} ^/index.html [NC] 
  6.  RewriteRule .* / [R=301,L] 
  7.  RewriteCond %{REQUEST_FILENAME} !-d 
  8.  RewriteCond %{REQUEST_FILENAME} !-f 
  9.  RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L] 
  10. </IfModule> 

即可。

广州vi设计公司http://www.maiqicn.com 我的007办公资源网 https://www.wode007.com

具体:

  1. RewriteEngine On 
  2. RewriteBase / 
  3.  
  4. # .htaccess伪静态301去掉index.html尾巴 
  5. RewriteCond %{HTTP_HOST} ^www.qdonger.com$ [NC] 
  6. RewriteCond %{REQUEST_URI} ^/index.html [NC] 
  7. RewriteRule .* / [R=301,L] 
  8.  
  9. # .htaccess伪静态301去掉index.php尾巴 
  10. RewriteCond %{HTTP_HOST} ^www.qdonger.com$ [NC] 
  11. RewriteCond %{REQUEST_URI} ^/index.php [NC] 
  12. RewriteRule .* / [R=301,L] 
 
 
原文地址:https://www.cnblogs.com/ypppt/p/13653461.html