Apache伪静态.htaccess有用代码

作者: zms! 日期: 2012.06.01 本文发布于2858天前 分类: Rewrite方法 相关:

1、移除url中的www

RewriteEngine On
RewriteCond %{HTTP_HOST} !^your-site.com$ [NC]
RewriteRule ^(.*)$ http://your-site.com/$1 [L,R=301]

2、防止热链
RewriteEngine On
#Replace ?mysite\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [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]

3、重定向所有的WordPress feeds 到 feedburner

RedirectMatch 301 /feed/(atom|rdf|rss|rss2)/?$ http://feedburner.com/yourfeed/
RedirectMatch 301 /comments/feed/(atom|rdf|rss|rss2)/?$ http://feedburner.com/yourfeed/

4、创建常规错误页面
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

5、强迫指定文件下载

ForceType application/octet-stream
Header set Content-Disposition attachment

ForceType application/octet-stream
Header set Content-Disposition attachment

6、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

7、从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

8、防止自动目录列表
Options -Indexes

9、压缩静态数据
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript

10、强制指定特定的编码
AddDefaultCharset UTF-8


返回上一页


讨论区

您尚未 登录,或请 注册

登 录 注 册


你可能也喜欢

nginx域名重写 不加www 转到加www. 2017.06.24,1 pv
nginx rewrite of discuz 2017.05.25,3 pv
手机访问电脑页面时跳转 2014.11.18,19 pv

在 JavaScript 文件中运行 PHP 代码 2014.10.08,10 pv
使用 .htaccess 缓存加速网站 2014.10.08,12 pv
强制 URL 以斜杠结尾 2014.10.08,9 pv