Shubhangi
Shubhangi

Reputation: 69

how to hide index.php from my url in yii framework

my code runs with url:

http://localhost/yii/index.php/Adminlogin

I want url to look like:

http://localhost/yii/Adminlogin

.htaccess file

Options +FollowSymLinks
IndexIgnore */*
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

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>',
        ),
    ),

Upvotes: 0

Views: 1042

Answers (5)

komu_Mkeya
komu_Mkeya

Reputation: 414

my htaccess would look like

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

and in main.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: 0

sensorario
sensorario

Reputation: 21620

Also, ... remember to AllowOverride in your main apache configuration:

<Directory "/path/to/your/yii.sample/web/">
    Options FollowSymLinks Multiviews
    MultiviewsMatch Any
    AllowOverride All
    Require all granted
    allow from all
</Directory>

Is it possible that your web/.htaccess is correct, but your apache never allowed your

Upvotes: 0

Vijay Wilson
Vijay Wilson

Reputation: 516

Try this

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php(.*) [NC]
RewriteRule ^(.*)index\.php(.*)$ http://%{HTTP_HOST}$1/$2 [R=301,L]

or

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php(.*) [NC]
RewriteRule ^index\.php(.*)$ http://%{HTTP_HOST}$1 [R=301,L]

Upvotes: 0

Manoj S Kadlag
Manoj S Kadlag

Reputation: 250

Use this in your main.php

'urlFormat'=>'path',
'showScriptName'=>false,

And in your htaccess use below,

RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]

Upvotes: 1

Callam
Callam

Reputation: 11539

RewriteRule ^ index.php [L] instead of RewriteRule . index.php

Upvotes: 1

Related Questions