Yii Framework Forum: unable to remove index.php in url - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

unable to remove index.php in url Rate Topic: -----

#1 User is offline   buknoy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 21-November 11

Posted 21 November 2011 - 01:05 AM

Good day,

I'm trying to get index.php removed from the url but for some reason, not able to get it to work. I've already check rewrite_module and set AllowOverride to All but still no go. Below is the .htaccess that i'm using as well as the configuration file for yii.

/** .htaccess **/
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 **/

<?php

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'real tax property management system',

// preloading 'log' component
'preload'=>array('log'),

// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'application.extensions.userLib.*',
),

'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'pickupapasswordhere',
),
),



'defaultController'=>'main',

// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),



/*'cache'=>array(
'class'=>'system.caching.CApcCache',
),
'db'=>array(
'connectionString' => 'sqlite:protected/data/blog.db',
'tablePrefix' => 'tbl_',
),*/
// uncomment the following to use a MySQL database

'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/',
),
'urlManager'=>array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(

),
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
// uncomment the following to show log messages on web pages
/*
array(
'class'=>'CWebLogRoute',
),
*/
),
),
)
);
0

#2 User is offline   buknoy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 21-November 11

Posted 21 November 2011 - 01:51 AM

I followed the instructions on this post(http://www.yiiframew....php#entry39541) but still not able to get it to work. Hope you could help me with this one.. Thanks
0

#3 User is offline   Felix Haberland 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 28-November 11

Posted 28 November 2011 - 08:47 AM

Hi buknoy,

could you please post the path where you stored the .htaccess file? Maybe its located in the wrong directory?

Best regards,
Felix
0

#4 User is offline   eclectus 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 22-November 11

Posted 05 December 2011 - 05:17 PM

your .htaccess has to be in the root of your app, the same directory where index.php sits.
0

#5 User is offline   dty 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 30-December 10
  • Location:Mount Laurel, New Jersey

Posted 07 April 2013 - 03:59 PM

did you figure this out? I am having the same issue.
0

#6 User is offline   Ravi Bhalodiya 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 61
  • Joined: 27-August 12
  • Location:Gujarat India

Posted 09 April 2013 - 02:05 AM

same problem here also.
In windows 7 it is not working.. But in ubuntu 12.04 its working perfectly.
main.php code :
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>/*'=>'<controller>/<action>',

'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',


'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>'=>'<module>/<controller>/<action>',


),
'showScriptName'=>false,
),

In .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]
Regards
Ravi Bhalodiya.
0

#7 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,317
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 April 2013 - 03:12 AM

For index.php to be removed mod_rewrite should be enabled so check that first.
Find more about me.... btw. Do you know your WAN IP?
1

#8 User is offline   dty 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 30-December 10
  • Location:Mount Laurel, New Jersey

Posted 09 April 2013 - 02:24 PM

View PostMaurizio Domba, on 09 April 2013 - 03:12 AM, said:

For index.php to be removed mod_rewrite should be enabled so check that first.


for me, it is enabled.
0

#9 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,317
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 April 2013 - 04:12 PM

Check this links to see if some solution fits your case:

http://www.yiiframew...hp/topic/12547-
http://www.yiiframew...hp/topic/15688-
http://www.yiiframew...hp/topic/39422-
Find more about me.... btw. Do you know your WAN IP?
1

#10 User is offline   Bilal Ahmed 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 24-May 12

Posted 20 April 2013 - 02:53 AM

I have made my urls seo friendly by doing the following simple steps,

Step 1:

In application root directory create a file named .htaccess, then edit the file in editor and paste the following content in it

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

Note, this rule will allow both of the of urls, with inex.php and without index.php

Step 2,

Now you can also tell yii to not use index.php in url,
For that you need to edit your protected/config/main.php

and in url manager array paste the following line,

'showScriptName'=>false,

as shown below

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

And that will be all

I have tested it on both windows and linux and it is working fine.
0

#11 User is offline   Albert St Clair 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 30-April 13
  • Location:London

Posted 02 May 2013 - 06:56 AM

It worked for me follow these instructions
.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

and adding following to my urlManager array

'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users