{
    分享网正式开通,我们为大家提供免费资源,欢迎大家踊跃投稿!

利用.htaccess实现首页index.html重写与栏目页重定向(完整版)

余斗在以前的文章中分别说了如何用.htaccess文件实现index.html跳转、Windows创建.htaccess文件方法总结和利用.htaccess文件实现网站栏目首页的301跳转,不少搜索相关问题进来的读者反应很多都实现不了,这可能是每个服务器的差异性造成。

余斗最近在弄公司的企业站,做完之后顺便把这一系列的跳转问题也解决了,因为公司的服务器是Apache的,所以只能用.htaccess文件来实现首页index.html重写与栏目页重定向,完整实现代码如下,大家可以参考使用:


<Files ~ "^.(htaccess|htpasswd)$">
deny from all
</Files>
#记得将余斗的域名yudouyudou换成您自己的哦!
#404页面
ErrorDocument 400 /404.htm
ErrorDocument 403 /404.htm
ErrorDocument 404 /404.htm

#www跳转
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(yudouyudou\.com)(:80)? [NC]
RewriteRule ^(.*) http://www.yudouyudou.com/$1 [R=301,L]

#栏目url重写
RewriteRule (.*)/index.html http://www.yudouyudou.com/$1 [L=301,R]
RedirectMatch 301 (.*)/list_(.*)_1.html$ $1

#index.html重写
RewriteCond %{HTTP_HOST} www.yudouyudou.com [NC]
RewriteCond %{REQUEST_URI}/index.html [NC]
RewriteRule .*/ [R=301,L]

order deny,allow
 

一个完整的.htaccess文件下载


套路很深,不支持下载!


爱资源分享网 , 版权所有丨本站资源仅限于学习研究,严禁从事商业或者非法活动!丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:利用.htaccess实现首页index.html重写与栏目页重定向(完整版)
喜欢 ()分享 (0)