.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] 这是最后一条规则,之后内容无用

原文地址:https://www.cnblogs.com/myvic/p/5790674.html