Ilan lewin
Ilan lewin

Reputation: 1639

Cannot get Yii urlManager to work

I am asking this after a couple of hours of searches. I just can't tell what I am missing here. I am trying to set friendly URLs for my Yii application.

  1. My base url is http://www.baby-registry.org/BABYREG/app/
  2. I am trying to change this url http://www.baby-registry.org/BABYREG/app/index.php?r=generalProducts/admin into http://www.baby-registry.org/BABYREG/app/productAdmin
  3. Using this in my main.php config file:

    'urlManager'=>array( 'urlFormat'=>'path', 'rules'=>array( ), ),

  4. Either with or without rules (tried different rules I found on stackoverflow), this breaks my app altogether, I get the famous notice 'Congratulations! You have successfully created your Yii application. You may change the content of this page by modifying the following two files:......'

What am I doing wrong? Does it have anything to do with the fact that I have a base url like (BABYREG/app)?

Upvotes: 0

Views: 1679

Answers (2)

Ben
Ben

Reputation: 57297

I just spent way too long with my array arguments reversed. Here's my first successful rewrite:

Link in app:

<a href='<?php echo Yii::app()->createUrl("home"); ?>'>Rewriting test</a>

PHP config:

'rules'=>array('successfully/rewritten' => 'home');

Note that it's desired url and then existing url. Backwards, in my head - I'd reckon it's "rewrite this, to this". Instead, it's "this is the rewrite for this." ^_^

Upvotes: 0

Brett Gregson
Brett Gregson

Reputation: 5923

You will need to post a bit more code, and also what error message (if any) you are getting.

But, a common reason for the URL rewriting not to work in Yii is that the apache module mod_rewrite is off. This apache module is required to use the Yii URL rewriting.

To check whether this module is enabled, in PHP, use apache_get_modules(); This will return an array of enabled apache modules. So a simple way to check if mode_rewrite is enabled is:

if (in_array('mod_rewrite', apache_get_modules())){
    // mod_rewrite is enabled
}

If it is not enabled, ask you hosting company to enable it for you. If you are working on your local host (with WAMP), simply enable it by clicking it under the apache menu - modules in the WAMP icon on the system tray

Upvotes: 0

Related Questions