WenRou's Blog
.htaccess 伪静态妙用
2015-3-17 温柔哥


# 將 RewriteEngine 模式打開

RewriteEngine On



Options +Indexes:顯示目錄下所有檔案

Options -Indexes:隱藏目錄下所有檔案 (上面已經介紹過)

IndexOptions +FancyIndexing:顯示目錄下所有檔案,檔案前面包含檔案類型的小圖示

IndexOptions -FancyIndexing : 顯示目錄下所有檔案,但不包含檔案類型的小圖示

IndexIgnore *.php *.exe:隱藏特定的檔案, 其餘檔案正常顯示(隱藏所有的php和exe檔案)



#自定义错误页面

ErrorDocument 404 /arc/404.html

ErrorDocument 503 /error-pages/service-unavailable.html



#IP禁止

Order allow,deny

Deny from 123.45.67.8

Deny from 123.123.7

Allow from all

#上面能禁止IP地址在123.45.67.8以及IP地址开头为123.123.7的任何人。例如123.123.74.42 就不能得到访问。



#变更默认首页

DirectoryIndex homepage.html



#去除页面广告(不一定适用所有免费空间)

LayoutIgnoreURI *.php

LayoutIgnoreURI *.cgi

LayoutIgnoreURI *.htm

LayoutIgnoreURI *.html

LayoutIgnoreURI *.txt



#页面跳转

Redirect page1.html page2.html

#如果某人访问 http://www.example.com/page1.html,他将被跳转到(带有HTTP状态代码302)的http://www.example.com/page2.html



#服务器内置SSI

AddType text/html .shtml

AddHandler server-parsed .shtml

Options Indexes FollowSymLinks Includes



#防盗链开启,支持泛域名

RewriteCond %{HTTP_REFERER} !^http://weidao.net.*$ [NC]

RewriteCond %{HTTP_REFERER} !^http(s)?://(.)+\.weidao\.net [NC]

RewriteRule .*\.(gif|GIF|jpg|JPG|mpg|MPG|mpeg|MPEG|wmv|WMV|rm|RM|zip|ZIP|rar|RAR|js|JS|css|CSS|txt|TXT)$ http://www.weidao.net/images/jinzhifanyue.jpg [NC,R,L]



#让指定域名访问指定根目录

DirectoryIndex index.php index.html index.htm

RewriteCond %{HTTP_HOST} ^t.weidao.net$

RewriteCond %{REQUEST_URI} !^/

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /$1

RewriteCond %{HTTP_HOST} ^t.weidao.net$

RewriteRule ^(/)?$ /blog/ [L]



# 网站301重定向

RewriteCond %{http_host} ^www.wenrouge.com [NC]

RewriteRule ^(.*)$ http://www.wenrouge.com [L,R=301]



# cPanel 开启Gzip

<ifmodule mod_deflate.c>

AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-httpd-php application/x-javascript

</ifmodule>

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容