Yii Framework Forum: How to remove index.php from URL - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

How to remove index.php from URL Rate Topic: ***** 2 Votes

#21 User is offline   HBK 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 06-December 11
  • Location:Bangalore

Posted 23 April 2012 - 01:25 AM

View PostDraz, on 23 March 2012 - 05:13 PM, said:

Hi,
I enabled the url manager and the index.php part in the url gets removed and works fin
my .htacsses file
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)

# otherwise forward it to index.php
RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]



the url manager works fine ut index.php doesn't go away in the url
so I added when I have showScriptName set to false in my config/main.php file
'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>',
	),


but now I get a 404 error whenever I click a link(because it removed index.php from the url)



Hi Draz,

I am getting the same error. Did you resolve your 404 error?? if yes please let me know the solution.

Thank you.
0

#22 User is offline   HBK 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 06-December 11
  • Location:Bangalore

Posted 07 May 2012 - 01:23 PM

I got the 404 error solved. I had to make a little change to my httpd.conf ..

<Directory "C:/Apache/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache....re.html#options
# for more information.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

</Directory>


Though i had AllowOverride set to 'All' for all directories, above directory pointing to htdocs override AllowOverride to None, so i was not able to get rid of index.php in URI.. Now changed it to ALL... Everything is working like a Gem..


Thank you.
HBK
0

#23 User is offline   mith mith 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 25-August 12

Posted 25 August 2012 - 09:01 AM

If it's not working even after putting all those rewrite rules in the .htacsses file, please check the .htacsses file location because by default it is located inside /protected folder.

.htacsses should be in the root location.
0

#24 User is offline   Nisanth thulasi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 10-July 12
  • Location:Kochi

Posted 12 January 2013 - 07:21 AM

Hi

i changed my main.php

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


but error showing that "Not Found"
Thanks
Nisanth Thulasi
0

#25 User is offline   Brian Nettles 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 26-January 13

Posted 26 January 2013 - 11:55 AM

I think this may be the piece you may have been missing. This in the httpd.conf file.

Quote

<Directory "/var/www/html">
Options Indexes FollowSymLinks

AllowOverride All

Order allow,deny
Allow from all

</Directory>

0

#26 User is offline   tannu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 11-October 12

Posted 23 February 2013 - 02:43 AM

how can hide index.php


edit webapp/protected/.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



and use 'showScriptName'=>false, in config/main



iapply these changes on localhost and
after these changes index.php has been hide but when we click on other links then that links are not working

there is not found error is occurred
0

#27 User is offline   lavket 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 22-October 11
  • Location:India

Posted 23 October 2013 - 01:09 AM

View PostHBK, on 22 April 2012 - 01:13 PM, said:

Hi,

I have a problem with .htaccess file. I have made the following configuration changes.

1. removed the commented lines for rewrite in httpd.conf file.

LoadModule rewrite_module modules/mod_rewrite.so

2. Created new .htaccess file in the root directory of the website (In the place where we have index.php file) with following content:

RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index.php)

# otherwise forward it to index.php
RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]


(I am using windows OS).

3. Updated the main.php in config with following info:

'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>',
),
'showScriptName'=>false,
),

Issue:

I am getting 404 error..

Please help me on this.

Thank you.



1.I think you must have not restarted your Apache Services. Check if there's a tick mark on it now. If not it is still not enabled.

2.I have successfully removed index.php (Both on Local and Windows Server). Place this file in the root directory.Same level as of "Protected folder".Find my .htacess code below :

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



3. Now config\main.php. Find my code below :

		'urlManager'=>array(
			'urlFormat'=>'path',
			'showScriptName'=>false,    //Add This Line
			'caseSensitive'=>false,     //Add This Line
			
			'rules'=>array(
			
				/*Home Page Start*/    
				'' => 'site/index',     //Note: See below
				/*Home Page End*/

                         ...
                         )..


NOTE : If your URL Management is successful, then you will not see site/index in your home url. As you can see in the above code, we have made it blank "''='site/index'"

HOPE THIS HELPS!! Cheers to YII. :D
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

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