2014-03-05 51 views
-3

How to remove "index.php" and also wants to remove "?r=". I want to make URLs user friendly.如何刪除的index.php和R =在Yii框架

如何刪除「的index.php」,也想刪除「R =」。我想讓URL用戶友好。

+1

可能重複的[如何在Yii框架中刪除index.php](http://stackoverflow.com/questions/9633649/how-to-remove-index-php-in-yii-framework) –

回答

2

做這些3個步驟:

  1. 開啓Apache網址重寫。你的項目的根

  2. 廣場的.htaccess

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

在配置保護/配置/ main.php集showScriptName假像這樣您的網址Manager組件>> urlManager

'urlManager'=>array(
    'urlFormat'=>'path', 
    'rules'=>array(
     '<controller:\w+>/<id:\d+>'=>'<controller>/view', 
     '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', 
     '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 
), 
    'showScriptName'=>false, 
) 
+0

如果您遇到像我剛纔那樣的問題 - 請確保「AllowOverride All」已設置在a ppache /etc/httpd/conf/httpd.conf文件 - 否則你的.htaccess文件不起作用! –

1

1)在受保護的>> config >> main.php中啓用您的urlManager,將這些行添加到數組中:

'urlManager'=>array(
     'urlFormat'=>'path', 
     'rules'=>array(
      '<controller:\w+>/<id:\d+>'=>'<controller>/view', 
      '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', 
      '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 
     ), 
    'showScriptName'=>false, 
    ), 

2).htaccess文件應該在站點根在同級別的index.php的,應該是這樣的:

RewriteEngine on 

    # if a directory or a file exists, use it directly 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond $1 !^(index\.php) 

    # otherwise forward it to index.php 
    RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA] 

3)確保你的Apache配置的AllowOverride所有不是沒有