1

I have this htaccess file:

RewriteEngine on
#if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

And I'm using Yii 1.1.15 (this site was taken from 1.1.13 version but such version is not available anymore for download, so I'm using it in a 1.1.15 framework install - althought it has no problem as far as I can see), having a conf/main.php file like:

<?php

return array(
    'basePath'=>dirname(dirname(__FILE__)),
    'name'=>'Grand Duval - Códigos premiados',
    'defaultController'=>'participantes/create',
    'language'=>'es',

    // preloading 'log' component
    'preload'=>array('log'),

    // autoloading model and component classes
    'import'=>array(
        'application.models.*',
        'application.components.*',
    ),

    'modules'=>array(
        'gii'=>array(
            'class'=>'system.gii.GiiModule',
            'password'=>'mypassword',
            'ipFilters'=>array('127.0.0.1', '::1'),
        ),
    ),

    // application components
    'components'=>array(
        'user'=>array(
            // enable cookie-based authentication
            'allowAutoLogin'=>true,
        ),

        '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>',
            ),
        ),

        'db'=>array(
            'connectionString' => 'mysql:host=localhost;dbname=mydatabase',
            'emulatePrepare' => true,
            'username' => 'sbuser',
            'password' => 'dbpassword',
            'charset' => 'utf8',
        ),

        'errorHandler'=>array(
            'errorAction'=>'site/error',
        ),
        'log'=>array(
            'class'=>'CLogRouter',
            'routes'=>array(
                array(
                    'class'=>'CFileLogRoute',
                    'levels'=>'error, warning',
                ),
            ),
        ),
    ),

    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
    'params'=>array(
        // this is used in contact page
        'adminEmail'=>'[email protected]',
    ),
);

The important part here is:

        '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>',
            ),
        ),

Such config is intended - and does work like that - to generate absolute urls like http://www.mydomain.dev/controller/action for controller controller and action action.

I have the problem with the .htaccess file: If I try to hit http://www.mydomain.dev/controller/action, the url is not found. However if I hit http://www.mydomain.dev/index.php/controller/action it is found. It looks that .htacccess has no effect at all (It is the exact same if I delete the .htaccess file).

Q: what am I doing wrong?

2 Answers 2

1

I think you need to enable mod_rewrite try:

a2enmod rewrite

Then just restart your server.

Sign up to request clarification or add additional context in comments.

2 Comments

No, it is enabled. Otherwise i'd get a 500 error. BTW I tried that command right now, and neither worked
Althought the answer you wrote was not the answer to my problem (I found it), it is a common problem people finds and I found some time ago. Ensuring mod_rewrite is active is not trivial in apache (althought it is trivial for its 'cousin' in nginx) and most of the times it is the solution. upvote :).
1

I found the answer. After ensuring that mod_rewrite was active for my other sites I asked myself: Is my .htaccess being recognized?

So i wanted to force a 500 error by corrupting my .htaccess file:

RewriteEngine on
# if a directory or a file exists, use it directly
TryToForceA500
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

And no error was triggered! So I asked myself -again-: Why isn't it being recognized? and checked my site .conf file and found:

AllowOverride none

And changed to:

AllowOverride all

(this is just a dev server, so that setup is fine for me)

And then the file was recognized and worked!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.