1
votes

I create a app by yiic. and then I tried to make a SEO url. I uncomment urlManager at [app root]/protected/config/main.php . And I add following into [app root]/.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

When I browse [app]/site/index, I got the error 404 - object not found. But if I browse by [app]/index.php?r=site/index, it is show me my app page. I followed many web sites by googling. but I got same error.

please help me to solve this one.

3

3 Answers

1
votes
Try to use this :

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

Instead of using .htaccess you can use urlManager in Yii to have custom url rules. Take a read at urlManager for details. I hope this post might also help to give you the idea. Controlling url in Yii: controller/action/id to /id

1
votes

I found the solution by myself. 1. uncomment urlManager at app/protected/config/main.php 2. create .htaccess file under app/ folder. (Important : not under app/protected/ folder) 3. copy and past the following code into new .htaccess file

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

That all. Thank you for your helping me, everybody.

0
votes

Check out this article on URL rewriting in Yii

Also, in your config, set showScriptName to false

'urlManager'=>array(
    'urlFormat' => 'path',
    'showScriptName' => false,
    ...