Yii, mamp, htaccess rewrite urls

I am trying to rewrite yii addresses but no luck. I spent hours going through sites, and each time I came up with the same answer, which does not work for me:

http://www.yiiframework.com/doc/guide/1.1/en/topics.url#user-friendly-urls

I would like to allow urls for base paths like

/index.php/site/index in /

/index.php/ads and /index.php/ads/ in / ads

/ advertisement / details? Ads = 9 in / ad / 9

The problem is that .htaccess has no effect.

I use:

mamp pro on mac with a lion and the web directory is different from the root web server . I installed AllowOveride through the console.

.htaccess is located in the same folder as the main index.php, but it does not register even if I create an error.

I had no problems with other non-yii web directories using htaccess file

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php

//main.php

  'urlManager'=>array(
        'urlFormat'=>'path',
                    'showScriptName'=>false,

        'rules'=>array(

                        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),
    ),
0
source share
1 answer

I have a project in which the Yii application is also located in a subfolder.

This is my .htaccess file:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

Then in main.php you need to add these lines to the "rules" array:

'' => 'site/index', // This is for the home page

Is the ad the name of your controller? In other words, do you have a file called AdsController.php in the controllers folder? If so, then it will work by default.

Just wondering why you click on index.php directly? You should be able to configure your local host to directly point to the Yii application folder. For example, on my machine, I created http: // mytestapp / and points to the application folder in htdocs.

Mac, etc/hosts...

:   127.0.0.1 mytestapp

, ...

+2

All Articles