Awan
Awan

Reputation: 18560

How to remove index.php from Yii URLs in Apache/Centos?

I am working with Yii Framework on Apache/2.2.15 (CentOS) Server.


Following line is uncommented in /etc/httpd/conf/httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so


I can see mod_rewrite under Loaded Module when I do following

<?php phpinfo(); ?>


Yii Project Structure:

/var/www/test/ 
/var/www/test/index.php 
/var/www/test/.htaccess


.htaccess content

RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php


It works fine when I do:

http://10.20.30.40/test/index.php/testcontroller/testaction


But when I do:

http://10.20.30.40/test/testcontroller/testaction

It shows following error:

Not Found

The requested URL /var/www/test/index.php was not found on this server.

Any idea?

Upvotes: 4

Views: 5823

Answers (4)

Xylum
Xylum

Reputation: 28

I solved this editing the Apache Configuration file at: {{ApacheDir}}/conf/httpd.conf
And Un-commenting / Adding the following line: LoadModule rewrite_module modules/mod_rewrite.so

Upvotes: 0

alsantos123
alsantos123

Reputation: 131

I have the same trouble. I use Apache config alias, like:

<VirtualHost *:80>
...

Alias /project "/Users/foo/Sites/project"

...
</VirtualHost>

To solve, I use "RewriteBase" directive on .htaccess, example:

RewriteEngine on
RewriteBase /project # <---- Modify here! and remove this comment.

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

Source: http://www.yiiframework.com/wiki/214/url-hide-index-php/#c9725

Upvotes: 4

PJ.
PJ.

Reputation: 1206

Ensure that AllowOverride is "All" for your project's web directory in httpd.conf. If not, change the value and restart the web server

Upvotes: 2

ineersa
ineersa

Reputation: 3435

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

htaccess content.

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

urlmanager config in your main.php. Or you can customize it if you want.

Upvotes: 2

Related Questions