我是新來的php,新的mvc,新的yii和新的URL重寫。所以,我很抱歉,如果我問一些非常基本的東西。Yii基本地址重寫
我有隱藏的index.php(從警予的論壇中討論的htaccess的方法)
在我urlmanager,我有這個,
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
),
'showScriptName'=>false,
我有鑑於/站點文件夾的3個文件。
- '旅程',
- '邀請',
- 'LinkedIn'
現在,我的主頁應該重定向到 '征途' 行動(即應打開「網站/旅程.PHP「)
所以,我想,這將是
'/' => 'site/journey'
它也可以。
現在,我想「之旅/邀請」應該調用「邀請」行動,即應該打開「網站/ invite.php」
而且,「征途/ LinkedIn」應該調用「LinkedIn」行動,即「網站/ linkedin.php」。
但是,
'journey/invite' => 'site/invite',
'journey/linkedin' => 'site/linkedin'
不工作。
此外,有人可以幫助我理解這一點,
<controller:\w+>/<id:\d+>
即是什麼控制器URL又是什麼 'W +' 是什麼意思?
對指南的參考也有幫助。
bool.dev的建議後編輯:
改變了代碼,就像你說的(我試過前面過,去除所有的默認規則)。 現在我的網址經理很喜歡,
'/' => 'site/journey',
'journey/invite' => 'site/invite',
'journey/linkedin' => 'site/linkedin',
'<controller:\w+>/<id:\d+>'=>'view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
但它拋出一個錯誤
"Warning: require_once(): open_basedir restriction in effect. File(/var/xyz.com/../yii/framework/yii.php) is not within the allowed path(s): (/usr/share/php:/usr/share/pear:/usr/share/php/libzend-framework-php:/var/*/tmp:/var/xyz.com) in /var/xyz.com/journey.php on line 12 Warning: require_once(/var/xyz.com/../yii/framework/yii.php): failed to open stream: Operation not permitted in /var/xyz.com/journey.php on line 12 Fatal error: require_once(): Failed opening required '/var/xyz.com/../yii/framework/yii.php' (include_path='.:/usr/share/php:/usr/share/php/libzend-framework-php') in /var/xyz.com/journey.php on line 12'
當我做xyz.com/journey/invite
甚至xyz.com/journey
編輯:
這是一個許可問題,@bool。開發的建議,把具體的規則之上的工作:)
好吧,在你添加我的建議之前它沒有工作時發生了什麼?我的意思是它不工作的方式?你有沒有顯示任何錯誤? – 2012-03-26 20:26:02
我也沒有工作。 它使用通常的語法,但在URL路由中引發錯誤。 我可以很容易地打開'xyz.com/site/journey'或'xyz.com/site/invite' 但是'xyz.com/journey'或'xyz.com/journey/invite'會拋出上面給出的錯誤。 – Jashwant 2012-03-26 20:33:59
我的htaccess文件有這段代碼來隱藏index.php文件。 '選項+的FollowSymLinks IndexIgnore */* RewriteEngine敘述上 #如果目錄或文件是否存在,直接使用它 的RewriteCond%{} REQUEST_FILENAME!-f 的RewriteCond%{} REQUEST_FILENAME!-d #否則轉發給index.php RewriteRule。 index.php' – Jashwant 2012-03-26 20:40:18