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

I work with the Yii Framework on an Apache / 2.2.15 server (CentOS) .


The following line is uncommented in /etc/httpd/conf/httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so 


I can see mod_rewrite in the loaded module when I execute

<?php phpinfo(); ?>


Yii project structure:

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


.htaccess

 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 this:

 http://10.20.30.40/test/testcontroller/testaction 

The following error is displayed:

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

Any idea?

+4
source share
4 answers

I have the same problem. I am using an Apache configuration alias, for example:

 <VirtualHost *:80> ... Alias /project "/Users/foo/Sites/project" ... </VirtualHost> 

To solve, I use the "RewriteBase" directive on .htaccess, for 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

+4
source
 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>'), 

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

+2
source

Make sure AllowOverride is "Everything" for your project web directory at httpd.conf. If not, change the value and restart the web server

+2
source

I decided to change the Apache configuration file at: {{ApacheDir}}/conf/httpd.conf
And Un-commenting / Adding the following line: LoadModule rewrite_module modules/mod_rewrite.so

0
source

Source: https://habr.com/ru/post/1482951/


All Articles