# 这是注释
# 指定默认首页查找顺序
DirectoryIndex index.htm .index.php
#自定义404页面
ErrorDocument 404 /error/404.html
#比较下面2句: 默认是302(临时性重定向),用户访问的是a目录,但实际显示的是b目录页面,地址栏显示的是b目录路径
redirect /a /b
#redirect 301 /a /b
#访问old.html实则显示的是index.php ,而地址栏依旧显示old.html,对比后面带中括号[]效果区别
RewriteEngine on
RewiteBase /
RewriteRule ^old.html$ index.php
#RewriteRule ^old.html$ /index.php [r=301]
#访问index.php需要验证账号密码,如果是进入目录要验证,只须去掉<Files>标签并把.htaccess文件放入对应目录既可
<Files "index.php">
AuthName "Username and passwordsss required"
# .htpasswd即验证账号密码保存文件,名称可自定义,但路径必须是带盘符的绝对路径,否则会报500 internal server error错误
AuthUserFile D:/Kuaipan/.htpasswd
Require valid-user
AuthType Basic
</Files>
.htpasswd文件格式如下,可加多个账号,每个账号单独一行即可:
username:password
#访问test.com跳转至www.test.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.com [NC]
RewriteRule ^(.*)$ https://www.test.com/$1 [L,R=301]
#图片防盗链:站外引用,直接跳转到google.com
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https://www.test.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^https://www.test.com$ [NC]
RewriteCond %{HTTP_REFERER} !^https://test.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^https://test.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|js|css|swf)$ https://www.google.com [R,NC]
# 参考文章
# http状态码:https://baike.baidu.com/view/1790469.htm
# .htaccess重定向和url重写: https://www.jb51.net/article/33608.htm
# .htaccess重定向和url重写:https://www.cnblogs.com/adforce/archive/2012/11/23/2784664.html
# chrome web development - network,status可查看http状态码
0条评论( 网友:0 条,站长:0 条 ) 网友评论{有您的评论更精彩....}