• .htaccess中Apache配置详解


    1.<IfDefine> 指令

    说明 封装一组只有在启动时当测试结果为真时才生效的指令

    语法 <IfDefine [!]parameter-name> ... </IfDefine> 

    作用域 server config, virtual host, directory, .htaccess 

    1.2 <IFModule mod_rewrite.c> </IFModule>

    说明 封装指令并根据指定的模块是否启用为条件而决定是否进行处理 

    语法 <IfModule [!]module-file|module-identifier> ... </IfModule> 
    作用域 server config, virtual host, directory, .htaccess 
    覆盖项 All 

    2.在Apache配置文件Apacheconf/httpd.conf中,设置

    <Directory />
      Options +Indexes +FollowSymLinks +ExecCGI
      AllowOverride All  #这里设置为all,none为禁止.htaccess
      Order allow,deny
      Allow from all
      Require all granted
    </Directory>

    3.创建.htaccess文件

    <IFModule mod_rewrite.c>

    #开启URL重写

    RewriteEngine On

    #请求内容不是目录

    RewriteCond %{REQUEST_FILENAME} !-d

    #请求内容不是文件

    RewriteCond %{REQUEST_FILENAME} !f

    #重写URL规则

    RewriteRule ^(.*)$ index.php /$1 [L]  #L:立即停止重写操作,并不再应用其他重写规则

    </IFModule>

    4.相关概念

    RewriteCond下:

     [NC] 不分字母大小写 

     [OR] 用于连接下一条规则  
    RewriteRule下: 
     [R] 强制重定向,[R=code] code默认为302

     [F] 禁用URL,返回HTTP 403 错误 

     [L] 这是最后一条规则,之后内容无用

  • 相关阅读:
    PHP调试的时候出现了警告:
    快报滚动
    js foreach、map函数
    箭头函数和普通函数的区别
    flex布局
    react+propTypes
    手机尺寸
    less的使用
    发现是在IE6-IE9下,下列元素table,thead,tfoot,tbody,tr,col,colgroup,html,title,style,frameset的innerHTML属性是只读的
    div+css 组织结构
  • 原文地址:https://www.cnblogs.com/myvic/p/5790674.html
Copyright © 2020-2023  润新知