- .htaccess, 控制Apache webserver,很有用,可以做很多的事情。本文介绍10个.htaccess 代码片段,web开发者需要收藏起来!
- 移除url中的www
- RewriteEngine On
- RewriteCond %{HTTP_HOST} !^your-site.com$ [NC]
- RewriteRule ^(.*)$ http://www.CodeSnippet.cn/$1 [L,R=301]
- 防止热链
- RewriteEngine On
- #Replace ?CodeSnippet\\.cn/ with your blog url
- RewriteCond %{HTTP_REFERER} !^http://(.+\\.)?CodeSnippet\\.cn/ [NC]
- RewriteCond %{HTTP_REFERER} !^$
- #Replace /images/nohotlink.jpg with your "don't hotlink" image url
- RewriteRule .*\\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]
- 重定向所有的WordPress feeds 到 feedburner
- <IfModule mod_alias.c>
- RedirectMatch 301 /feed/(atom|rdf|rss|rss2)/?$ http://Www.CodeSnippet.Cn/yourfeed/
- RedirectMatch 301 /comments/feed/(atom|rdf|rss|rss2)/?$ http://Www.CodeSnippet.Cn/yourfeed/
- </IfModule>
- 创建常规错误页面
- ErrorDocument 400 /errors/badrequest.html
- ErrorDocument 401 /errors/authreqd.html
- ErrorDocument 403 /errors/forbid.html
- ErrorDocument 404 /errors/notfound.html
- ErrorDocument 500 /errors/serverr.html
- 强迫指定文件下载
- <Files *.xls>
- ForceType application/octet-stream
- Header set Content-Disposition attachment
- </Files>
- <Files *.eps>
- ForceType application/octet-stream
- Header set Content-Disposition attachment
- </Files>
- PHP 错误日志
- # display no errs to user
- php_flag display_startup_errors off
- php_flag display_errors off
- php_flag html_errors off
- # log to file
- php_flag log_errors on
- php_value error_log /location/to/php_error.log
- 从URL中移除文件拓展名,如.html
- RewriteEngine on
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteCond %{REQUEST_FILENAME}\\.html -f
- RewriteRule ^(.*)$ $1.html
- # Replace html with your file extension, eg: php, htm, asp
- 防止自动目录列表
- Options -Indexes
- 压缩静态数据
- AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/CSS application/x-javascript
- 强制指定特定的编码
- <FilesMatch "\\.(htm|html|css|js)$">
- AddDefaultCharset UTF-8
- </FilesMatch>
- //该片段来自于http://www.codesnippet.cn/detail/311020136847.html
来源: http://www.codesnippet.cn/detail/311020136847.html