2015-04-17 54 views
0

如果我在URL中隱藏(通過.htaccess或php代碼重定向)index.php名稱腳本,規則將停止工作(404 errror)。yii urlManager:如果隱藏index.php,則停止工作規則

這意味着http://site.ru/index.php/test在開始工作,http://site.ru/test現在不工作。
我能做什麼?

'urlManager'=>array(
    'urlFormat'=>'path', 
    'showScriptName'=>false, 
    'rules'=>array(
     'test'=>'site/index', 
    ), 

我添加它:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . index.php 

一切都很好,但現在我的404規則是不工作...

(ErrorDocument 404  /404.html) 


回答
如果您不想要動態404頁面(默認在警予網站/錯誤),然後改變它:

RewriteRule . index.php 


RewriteRule .* /404.html 
+0

這可能有助於http://stackoverflow.com/questions/13542560/removing-index-php-from-url-cause-404-in-yii?rq=1 – RajeshK

+0

請現在在.htaccess中分享您的重定向規則 –

+0

我的404規則不起作用 –

回答

0

你必須創建main.php工作正常的路由規則,但是你有沒有告訴Apache爲忽略.htaccess中的重定向規則。如果您使用的是Linux然後/etc/apache2/sites-available/

<Directory "/baepath/to/application"> 
AllowOverride All 
#... 
</Directory> 

或者更經常在創建一個允許過乘坐規則,你可以通過創建項目的新目錄規則創建虛擬環境。