.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配置文件Apache\conf/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] 這是最后一條規則,之后內容無用

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM