• 保存到桌面  加入收藏  设为首页
Web综合

301跳转代码脚本(301永久跳转、302临时跳转)和自定义404和503错误页

时间:2016-10-21 21:27:34   作者:江节胜   来源:胜行天下   阅读:743   评论:0

      Windows主机检查web.config,Linux主机检查.htaccess文件

     (详见http://jingyan.baidu.com/article/066074d694ab77c3c31cb077.html

 

    htaccess中

    同时自定义404和503错误页面的方法。同样新建个记事本,输入以下代码:

<Files ~ "^.(htaccess|htpasswd)$">
deny from all
</Files>
ErrorDocument 404 /404gy.php
#ErrorDocument 503 /503.html
order deny,allow

 

web.config 书写注意事项:不能有空行、不能有注释,否则有内部错误。

 

 

    比较常见的301跳转代码脚本:采用方法2(放在根目录下。去掉注释)
1.IIS6实现301代码.htaccess
  1. <IfModule mod_rewrite.c>
  2. Options +FollowSymLinks
  3. RewriteEngine On
  4. RewriteCond %{HTTP_HOST} ^023ctrip.com [NC,OR]
  5. RewriteCond %{HTTP_HOST} ^ww.023ctrip.com [NC]
  6. RewriteRule ^(.*)$ http://www.023ctrip.com/$1 [L,R=301]
  7. </IfModule>
2.IIS7/7.5实现301代码web.config  (实测可用)
  1. <configuration>
  2. <system.webServer>
  3. <rewrite>
  4.     <rules>
  5.        <rule name="blog301" stopProcessing="true">
  6.          <match url="^(.*)$" ignoreCase="false" />
  7.            <conditions logicalGrouping="MatchAll">
  8.               <add input="{HTTP_HOST}" pattern="^wcniis.net"/> //正式使用时去掉此注释 只需换wcniis.net 多个域名用$|^
  9.            </conditions>
  10.          <action type="Redirect" url="http://www.wcniis.net/{R:1}" redirectType="Permanent" />
  11.        </rule>
  12.     </rules>
  13. </rewrite>
  14. </system.webServer>
  15. </configuration>
注意:多个域名用$|^  比如:<add input="{HTTP_HOST}" pattern="^wcniis.cn$|^w.wcniis.cn" />
3.
linux下apache实现301代码
  1. RewriteEngine on
  2. # 把 mangguo.org 改为你要绑定的域名
  3. RewriteCond %{HTTP_HOST} ^(www.)?qgqzx.gov.cn$

  4. # 把 subfolder 改为要绑定的目录.
  5. RewriteCond %{REQUEST_URI} !^/qgzx/

  6. # 不要改以下两行
  7. RewriteCond %{REQUEST_FILENAME} !-f
  8. RewriteCond %{REQUEST_FILENAME} !-d

  9. # 把 subfolder 改为要绑定的目录
  10. RewriteRule ^(.*)$ /qgzx/$1

  11. # 把 mangguo.org 改为你要绑定的域名
  12. # 把 subfolder 改为要绑定的目录.
  13. # subfolder/ 后面是首页文件index.php, index.html...

  14. RewriteCond %{HTTP_HOST} ^(www.)?qgqzx.gov.cn$
  15. RewriteRule ^(/)?$ qgzx/index.htm [L]

  16. 如: RewriteEngine On
  17. RewriteBase /
  18. RewriteCond %{http_host} ^http://wcniis.cn[NC]
  19. RewriteRule ^(.*)[        DISCUZ_CODE_62        ]nbsp;http://www.wcniis.cn/$1 [L,R=301]
注意:以上301代码供参考 具体以服务器配置及环境要求为准 感谢大家的支持!

 

有任何疑问或技术合作都可联系我

微信:yanfahezuo 【推荐】

QQ:596957738


上一篇:关于默认首页设置和生成首页静态页面
下一篇:没有了
相关评论

加我微信 596957738 (QQ同号)加我微信     QQ联系:596957738    地址:江苏省南京市浦口区

苏ICP备2023050353号

   

苏公网安备32011402010305号

江节胜的Gitee,江节胜的Git地址