2012-07-24 32 views
0

重定向頁面我有網址: -我想在CakePHP中

http://mydomain/test/index.html 

我想,當用戶將URL輸入: - http://mydomain/test

它會重定向到http://mydomain/test/index.html ..

什麼我試過我給路由代碼。

Router::connect('/', array('controller' => 'enrollments', 'action' => 'index')); 

我想重定向到index.html頁面如何給..

+0

index.html頁面究竟在哪裏?你把它放在app/webroot/test /中嗎? – JJJ 2012-07-24 12:26:14

+0

不,它只在webroot上。 – 2012-07-24 12:54:43

+0

您無法訪問webroot中的index.html。 index.php優先,你不能刪除它,否則CakePHP停止工作。爲什麼你需要有一個靜態html文件,你不能將它添加爲一個靜態的CakePHP動作並將根重定向到那個? – JJJ 2012-07-24 13:14:02

回答

1

Pages Controller通常用於提供靜態網頁。例如。如果您創建視圖文件* app/views/pages/about_us.ctp *,則可以使用url * http://example.com/pages/about_us*來訪問它。

如果您有baked your app,Pages控制器應該已被複制到您的app/controllers/文件夾中,並且可以修改它,或者您可以將pages_controller.php從核心複製到您的應用程序。但是,如果您不需要修改它,即只顯示靜態內容,則不需要將頁面控制器複製到app/controllers/

如何顯示靜態頁面?

那麼,如果你使一個視圖文件app/views/pages/index.ctp你可以使用url http://example.com/pages/index來訪問它。然後修改航線,您可以:

Router::connect('/test', array('controller' => 'pages', 'action' => 'display', index)); 

然而,這將不提供http://www.example.com/test/index.html而是:http://www.example.com/test/index

+0

+1幫助謝謝。我想在這個網址相同的結果; http://www.example.com/test/我的意思是當我運行它時,它將重定向到http://www.example.com/test/index.html .. – 2012-07-25 05:39:30

+0

你可以使用[Router Extensions](http ://book.cakephp.org/1.3/en/view/945/Routes-Configuration#File-extensions-952),但這會影響整個應用程序。我的建議,就是保持原樣。 – 2012-07-25 06:08:46