我的 .htaccess 文件的内容

把博客搬家了,然后突然发现 .htaccess 文件全丢失了,怎么办?哎,凭着记忆重新写了一份……现在赶紧在此备份一下。当然,你如果需要的话,也可以复制走,但是一些地方别忘记改了哟!

#索引设置
Options All -Indexes

#域名重定向
RewriteEngine On
RewriteCond %{HTTP_HOST} !^shansing.com$ [NC]
RewriteRule ^(.)$ //shansing.com/$1 [R=301,L]

RewriteRule ^id-(.).html$ /shansing-beta-is-not-sb/ [R=301,L]
Redirect permanent /future-posters/ /sitemap/

# Wordpress 伪静态
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

#优化的 Wordpress 伪静态
#RewriteEngine on
#RewriteBase /
#RewriteCond $1 ^(index.php)?$ [OR]
#RewriteCond $1 .(gif|jpg|png|rar|zip|7z|css|js|ico|gz)$ [NC,OR]
#RewriteCond %{REQUEST_FILENAME} -f [OR]
#RewriteCond %{REQUEST_FILENAME} -d
#RewriteRule ^(.)$ - [S=1]
#RewriteRule . /index.php [L]

#Gzip 识别
<Files .css.gz>
AddEncoding gzip .css
ForceType text/css
</Files>
<Files .js.gz>
AddEncoding gzip .js
ForceType application/x-javascript
</Files>

#文件缓存
<FilesMatch ".(jpg|gif|png|ico|css|js|woff)$">
Header set Cache-Control "max-age=3535888"
</FilesMatch>

#防盗链
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+X470X)?shansing.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule ..(jpg|gif|bmp|png|rar|zip|7z)$ //shansing.com/star/blank.html [L]

#文件保护
#保护 wp-config.php
<Files wp-config.php>
Order Deny,Allow
Deny from All
</Files>
#保护 .htaccess
<Files .htaccess>
Order Deny,Allow
Deny from All
</Files>
#保护 .maintenance
<Files .maintenance>
Order Deny,Allow
Deny from All
</Files>
#保护 readme.html
<Files readme.html>
Order Deny,Allow
Deny from All
</Files>
#保护 license.txt
<Files license.txt>
Order Deny,Allow
Deny from All
</Files>

什么什么?不知道 .htaccess 有什么用?简单来说,.htaccess 文件是 Apache 服务器中的一个配置文件,它负责相关目录下的网页配置。通过 .htaccess 文件,可以帮我们实现:网页301重定向、自定义404错误页面、改变文件扩展名、允许/阻止特定的用户或者目录的访问、禁止目录列表、配置默认文档等功能。

更新!2012年1月11日

若无特别说明,本文系原创,遵循 署名-非商业性使用 3.0 (CC BY-NC 3.0) 协议,转载文章请注明来自【闪星空间】,或链接上原文地址:http://shansing.com/read/51/

8 条评论

  1. 留个记号,备用

    1. 搬家了,不需要 .htaccess 了!

  2. 我是Ngnix.

    1. 俺现在又搬家了,也是 Ngnix 的了!

      1. Ngnix 才是王道

        1. 嘿嘿,你博客的欢迎词很吸引眼球:乍一看,怎么还有我的域名捏?

  3. 不会用啊,交换个链接吧

    1. 多搜索多学习,呵呵。交换链接请移步至“链接仓库”,在顶部导航能看到。

发表评论»

NO SPAMS! 不要发垃圾评论哦!

表情