Yii apache配置站點出現400 Bad Request 的解決方法

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "/www/frogCms/web"
  <Directory "/www/frogCms/web/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local</Directory>
  
    # 開啓 mod_rewrite 用於美化 URL 功能的支持(譯註:對應 pretty URL 選項)
    RewriteEngine on
    # 若是請求的是真實存在的文件或目錄,直接訪問
    RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # 若是請求的不是真實文件或目錄,分發請求至 index.php  RewriteRule . index.php # if $showScriptName is false in UrlManager, do not allow accessing URLs with script name RewriteRule ^index.php/ - [L,R=404]
</VirtualHost>

可是這樣會出現 400 Bad Request 錯誤。php

解決方法:rewrite規則放到Directory中web

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "/www/frogCms/web"
    <Directory "/www/frogCms/web/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
    
    # 開啓 mod_rewrite 用於美化 URL 功能的支持(譯註:對應 pretty URL 選項)
    RewriteEngine on
    # 若是請求的是真實存在的文件或目錄,直接訪問
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # 若是請求的不是真實文件或目錄,分發請求至 index.php
    RewriteRule . index.php

    # if $showScriptName is false in UrlManager, do not allow accessing URLs with script name
    RewriteRule ^index.php/ - [L,R=404]
    
  </Directory>

</VirtualHost>

重啓apache,OKapache

相關文章
相關標籤/搜索