.htaccess php设置,.htaccess更改php的配置

php_value 在.htaccess 中的使用

1、php_value memory_limit 64M //设置记忆缓存大小

2、ErrorDocument 404 errors/404.html //指定404错误的页面

3、DirectoryIndex index.html index.php index.htm //设置首页默认访问的文件名以及各式

4、Redirect 301 /old/file.html http://yourdomain.com/new/file.html 重定向文件

5、RedirectMatch 301 /blog(.*) http://yourdomain.com/$1 //批量重定向地址

6、设置浏览器缓存

Header set Cache-Control "public"

Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"

Header unset Last-Modified#2 hours

Header set Cache-Control "max-age=7200, must-revalidate"

SetOutputFilter DEFLATE

Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"

7、启用Gzip 设置压缩文件的类型

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.*

上面的代码是需要开启模块的支持的 如果没开启

加上这段代码

php_value output_handler ob_gzhandler

8、重定向页面到https ( ssl )

RewriteEngine On

RewriteCond %{HTTPS} !on

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

9、url重写 也就是伪静态

例子1:

重写

product.php?id=12 为 product-12.html

RewriteEngine on

RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1

例子2:

重写

yoursite.com/user.php?username=xyz 为 yoursite.com/xyz

RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1

RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1

括号内的数据表示参数的值 从左到右 一次为 $1 $2 命名

10、重定向 域名都指向到www域名下301

RewriteEngine On

RewriteCond %{HTTP_HOST} ^yonghappyl\.com$

RewriteRule (.*) https://www.yonghappy.com/$1 [R=301,L]

11、重定向域名到子文件

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.yonghappy.com\.com$ [OR]

RewriteCond %{HTTP_HOST} ^www\.www.yonghappy.com\.com$

RewriteCond %{REQUEST_URI} !^/new/

RewriteRule (.*) /new/$1

12、防止目录列表

Options -Indexes

或者

IndexIgnore *

13、添加新的MIME类型

文件的类型取决于文件扩展名。在下载的时候未被承认的文件扩展名被视为文本数据或者是损坏的。

AddType application/x-endnote-connection enz

AddType application/x-endnote-filter enf

AddType application/x-spss-savefile sav

14、拒绝访问静态文件数据

比如图片css js 如果不是本地站点的话

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]

RewriteCond %{HTTP_REFERER} !^https://www.yonghappy.com.*$ [NC]

RewriteRule \.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$ - [F,NS,L]

15、php上传文件参数限制参数设置

php_value upload_max_filesize 20M

php_value post_max_size 20M

php_value max_execution_time 200

php_value max_input_time 200

16、不允许脚本执行

Options -ExecCGI

AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi

17、更改字符编码和语言标题

AddDefaultCharset UTF-8

DefaultLanguage en-US

18、设置默认的地区时间

SetEnv TZ America/Indianapolis

19、强制文件另存为提示

AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4

20、设置cookie

Header set Set-Cookie "language=%{lang}e; path=/;" env=lang

---------

RewriteEngine On

RewriteBase /

RewriteRule ^(.*)(de|es|fr|it|ja|ru|en)/$ - [co=lang:$2:.yourserver.com:7200:/]

21、设置自定义标题

Header set P3P "policyref=\"https://www.yonghappy.com/w3c/p3p.xml\""

Header set X-Pingback "https://www.yonghappy.com/xmlrpc.php"

Header set Content-Language "en-US"

Header set Vary "Accept-Encoding"

22、根据用户请求头阻塞用户请求

SetEnvIfNoCase ^User-Agent$ .*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures) HTTP_SAFE_BADBOT

SetEnvIfNoCase ^User-Agent$ .*(libwww-perl|aesop_com_spiderman) HTTP_SAFE_BADBOT

Deny from env=HTTP_SAFE_BADBOT

支持博主

fe504e0de4e84d9b6ec42e5ca910afb4.png用金钱来联络感情吧~

心晴客栈 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明.htaccess更改php的配置!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值