2014-06-22 59 views
1

我有,我想URL像SiteURL/about.html.YII網址如何生成新的URL

config/main.php已經改變了代碼,但是當我登錄到網站,然後得到,當我瀏覽到任何其他網頁會話過期一個網站。

如果評論此代碼'showScriptName'=>falseconfig/main.php文件,那麼它的做工精細,現在我的登錄會話被保存,我們沒有過期但現在我的網址正在成爲這樣SiteURL/index.php/about.html

但我想URL像about.html.

我也有另一個控制器的遊戲選項的URL是這樣的:http://www.demo.com/index.php/Games/info/9.html但我想在這個「黑色鉤子」中的SiteURL/black-hook.html這樣的URL是遊戲的名稱。

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

* SITEURL = http://www.demo.com

+0

請發佈您的.htaccess。 – lin

+0

順便說一句。爲什麼「.html」? Yii是基於PHP的! – lin

回答

0

第一個拿到的.html添加到您的網頁,需要用假網址後綴選項urlManager

這可以通過添加'urlSuffix' =>'.html'urlManager配置來完成像這

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

其次爲隱藏index.php(稱爲條目腳本)在您的URL在一個在這裏改變配置,你需要改變你的apache/nginx服務器的配置。

創建包含以下內容的文件/.htaccess並保存

RewriteEngine on 

# if a directory or a file exists, use it directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# otherwise forward it to index.php 
RewriteRule . index.php 

下一步驗證,如果AllowOveride All是有你的應用程序目錄中的Apache配置文件也可以直接添加上面的配置添加到您使用目錄元素而不使用.htaccess的apache配置文件。 注:對於這個工作,你需要在Apache的配置啓用重寫引擎,你可以用下面的命令集,這樣做

a2enmod rewrite 

最後重新啓動的Apache2後

/etc/init.d/apache2 restart 

service apache2 restart 
+0

嗨,謝謝你我已經嘗試過,但有一段時間用戶成爲會議註銷,並且用戶無法在網站登錄,你能幫我,那裏是我在這裏失去什麼? – Amrish