Reputation: 390
Initial problem:
Hi I have a newly made Yii site where I want to remove the index.php from the URL.
Example: "/index.php/site/index" should be "/site/index"
I have been using this http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x guide but i only receive 404.
I hope that you are able to point a mistake or help me debug this problem!
Please let me know if I have left out any relevant information.
OBS: The "home" page works as intended, other pages are broken.
Status of the problem: It seems like it is an apache/ubuntu problem with mod_rewrite.so
After help from different people it all works now :D I had to install "rewrit" to get it running, i did that by writing Running a2enmod rewrit The below configuration of my system solved the problem for me, I hope this thread will help others in similar problems.
Server version: Apache/2.2.22 (Ubuntu)
Server built: Nov 8 2012 21:37:45
<Directory "/var/www/MY_SITE/FOLDER_CONTAINING_YII/">
AllowOverride All
#...
</Directory>
LoadModule rewrite_module modules/mod_rewrite.so
This is the entire content of the file
File does not exist: /.../htdocs/site, referer: http://.../htdocs/index.php/site/index
I added the dots
kah@webaalborg:/etc/apache2/sites-available$ sudo service apache2 restart
* Restarting web server apache2
[Mon Nov 26 20:16:35 2012] [warn] module rewrite_module is already loaded, skipping
... waiting
[Mon Nov 26 20:16:36 2012] [warn] module rewrite_module is already loaded, skipping
[ OK ]
...
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /var/www/MY_SITE>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
...
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
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
Upvotes: 3
Views: 5765
Reputation: 1
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride all <---- ***change this line***
Order allow,deny <---- ***change this line***
allow from all
Require all granted
</Directory>
Upvotes: 0
Reputation: 242
Try to put this into .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
And also remove the line 'LoadModule rewrite_module modules/mod_rewrite.so' from httpd.conf and enable the rewrite module from command line, executing a2enmod rewrite.
Upvotes: 0
Reputation: 927
If you are working on Linux(say ubuntu) then go to the path /etc/apache2/sites-available/
there you will find a file named as default
,
<Directory /var/www/> <--- ***root directory***
Options Indexes FollowSymLinks MultiViews
AllowOverride all <---- ***change this line***
Order allow,deny
allow from all
</Directory>
and i think your problem will resolve.
Thanks.
Upvotes: 5
Reputation: 47945
Do you AllowOverride
in your directory directive?
<Directory "/your/path">
AllowOverride All
#...
</Directory>
If not this would explain why your rewrite rules does not work.
Upvotes: 1