Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 467
Awan Avatar asked Feb 17 '23 10:02

Awan


1 Answers

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

like image 189
alsantos123 Avatar answered Feb 18 '23 23:02

alsantos123