10段有用的.htaccess代码
来源:互联网 发布:c指针例题编程 编辑:程序博客网 时间:2024/05/20 04:08
[代码] 移除url中的www
- RewriteEngine On
- RewriteCond %{HTTP_HOST} !^your-site.com$ [NC]
- RewriteRule ^(.*)$ http://your-site.com/$1 [L,R=301]
- Source: http://css-tricks.com/snippets/htaccess/www-no-www/
[代码] 防止热链
- 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]
[代码] 重定向所有的WordPress feeds 到 feedburner
- <IfModule mod_alias.c>
- RedirectMatch 301 /feed/(atom|rdf|rss|rss2)/?$ http://feedburner.com/yourfeed/
- RedirectMatch 301 /comments/feed/(atom|rdf|rss|rss2)/?$ http://feedburner.com/yourfeed/
- </IfModule>
- Source: http://www.wprecipes.com/how-to-redirect-wordpress-rss-feeds-to-feedburner-with-htaccess
[代码] 创建常规错误页面
- 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
- Source: http://css-tricks.com/snippets/htaccess/custom-error-pages/
[代码] 强迫指定文件下载
- <Files *.xls>
- ForceType application/octet-stream
- Header set Content-Disposition attachment
- </Files>
- <Files *.eps>
- ForceType application/octet-stream
- Header set Content-Disposition attachment
- </Files>
- Source: http://www.givegoodweb.com/post/30/forcing-a-download-with-apache-and-htaccess
[代码] 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
- Source: http://css-tricks.com/snippets/htaccess/php-error-logging/
[代码] 从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
- Source: http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess
[代码] 防止自动目录列表
- 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>
- Source: http://www.askapache.com/htaccess/setting-charset-in-htaccess.html
0 0
- 10段有用的.htaccess代码
- 10段有用的.htaccess代码
- 有用的css代码段
- 10个超级有用的PHP代码小片段
- 10段超有用的Git命令行代码
- 10段超有用的Git命令行代码
- 一些有用的JS 代码段
- JQuery有用的50段代码
- php有用的代码段-(1)
- 10+ 优化网站的 .htaccess 代码片段
- 直接拿来用!10段超有用的Git命令行代码
- 直接拿来用!10段超有用的Git命令行代码
- 直接拿来用!10段超有用的Git命令行代码
- 几个有用的Apache下.htaccess设置
- 常用的.htaccess代码片段
- 常用的.htaccess代码片段
- 常用的.htaccess代码片段
- 两段有用的函数
- 搭建WAMP server环境后,local host 80端口被占用的解决方案
- 关于我,关于博客
- 复制表结构
- 获取datatable的列名
- IOS6及以后如何标识不同设备&获取用户的唯一标示符
- 10段有用的.htaccess代码
- 关于数据库索引的简介
- android:打开系统联系人界面并获取数据
- iOS触摸事件处理
- SpringMVC配置文件的补充
- 小白书训练-Andy's First Dictionary
- PHP setcookie() cannot modify header information 的解决方法
- Tomcat优化配置
- iPhone6分辨率与适配