WenRou's Blog

新浪微薄腾讯微薄

最新碎语:测试图片碎语哦

您的位置:WenRou's Blog >lnamp> .htaccess 伪静态妙用

.htaccess 伪静态妙用

# 將 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>

---

转载请注明本文标题和链接:《.htaccess 伪静态妙用

发表评论

10 + 1 =
路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交