首页 > Apache > Apache .htaccess 常用配置代码

Apache .htaccess 常用配置代码

#重定向为小写字符串
RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]

#重定向 favicon.ico 和 favicon.gif
RedirectMatch 301 favicon\.ico http://zhuohang.tk/favicon.ico
RedirectMatch 301 favicon\.gif http://zhuohang.tk/favicon.ico

#定义404错误页
ErrorDocument 404 errors/404.html

#设置环境变量
SetEnv APPLICATION_ENV development

#设置对应文件类型的缓存时间,提高网站访问速度
#1 按某个时间点设置缓存时间
<FilesMatch “\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$”>
Header set Cache-Control “public”
Header set Expires “Fri, 23 September 2011 20:00:00 GMT”
Header unset Last-Modified
</FilesMatch>

#2 html,htm,xml,txt,xsl类的文件缓存7200秒
<FilesMatch “\.(html|htm|xml|txt|xsl)$”>
Header set Cache-Control “max-age=7200, must-revalidate”
</FilesMatch>

#3 由DEFLATE过滤器实现输出压缩,并按时间点设置缓存时间
<FilesMatch “\.(js|css)$”>
SetOutputFilter DEFLATE
Header set Expires “Fri, 23 September 2011 20:00:00 GMT”
</FilesMatch>

#使用 GZIP 压缩输出,需要服务器支持 GZIP 模块
<IfModule mod_gzip.c>
mod_gzip_on       Yes
mod_gzip_dechunk  Yes
mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler   ^cgi-script$
mod_gzip_item_include mime      ^text/.*
mod_gzip_item_include mime      ^application/x-javascript.*
mod_gzip_item_exclude mime      ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

#跳转 不带www的URL 为 www开头的URL
RewriteEngine On
RewriteCond %{HTTP_HOST} ^viralpatel\.net$
RewriteRule (.*) http://www.viralpatel.net/$1 [R=301,L]

#自动在头部加入字符集与语言
AddDefaultCharset UTF-8
DefaultLanguage ens-ES

#发送自定义头部
Header set X-Pingback “http://www.askapache.com/xmlrpc.php&#8221;
Header set Content-Language “es-ES”

分类:Apache 标签:,
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: