3

I search how to remove index.php in yii. it's working fine, but
How to remove index.php in Yii Framework

protected/config/main.php

'urlManager'=>array(
        'urlFormat'=>'path',
        'showScriptName'=>false,
        'rules'=>array(
            'redirect/<redirectUrl>'=>'site/index',
            'login'=>'site/login',
            'privacy'=>'site/privacy',
            'password'=>'site/forgot',
            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),
    ),

my htaccess file

DirectoryIndex index.php
<IfModule mod_rewrite.c>
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
</IfModule>

when i check the following url

yii.mywebapp.com/index.php?redirecturl=http://www.google.com

it's working but i removed index.php

yii.mywebapp.com/?redirecturl=http://www.google.com

it's also working

but i need when some user request redirect url with yii.someurl.com/index.php?redirecturl=someurl i want to hide index.php in the url

please help

1 Answer 1

4

Place this rule just below your RewriteEngine On line:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)index\.php([^\s]*) [NC]
RewriteRule ^ /%1%2 [R=301,L,NE]
Sign up to request clarification or add additional context in comments.

1 Comment

thanks anubhava it's working nice..once again thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.