子目录绑定域名,通过url重写规则将子目录重定向到二级域名的解决方法

时间:2017-11-11 21:06:03

分类:优秀文章

我们经常需要给子目录绑定二级域名,例如 http://www.cmsdx.com/dgmoban/ 绑定域名后就是 http://dgmoban.cmsdx.com ,但这样通过目录还是可以访问的,造成了重复内容,不利于seo。

下面我们来看一下通过地址重写来实现301重定向,其实就是我们用到的伪静态规则。

Apache版(放入.htaccess中):

折叠XML/HTML 代码
  1. RewriteRule ^dgmoban/(.*)$   http://dgmoban.cmsdx.com/$1 [R=301,L]  

IIS7版本(放入web.config中):

折叠XML/HTML 代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <configuration>  
  3.     <system.webServer>  
  4.         <rewrite>  
  5.             <rules>  
  6.                 <rule name="目录重写" stopProcessing="true">  
  7.                     <match url="^dgmoban/(.*)$" ignoreCase="false" />  
  8.                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />  
  9.                     <action type="Redirect" url="http://dgmoban.cmsdx.com/{R:1}"/>  
  10.                 </rule>  
  11.             </rules>  
  12.         </rewrite>  
  13.     </system.webServer>  
  14. </configuration>  

 

相关文章

相关推荐

为帝国CMS用户提供动力

Copyright © 2016 CmsDX.com All Rights Reserved.