Part of the EllisLab Network
   
 
Issues removing index.php from my urls
Posted: 20 November 2008 04:20 PM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  12
Joined  10-06-2008

I don’t know if this is the best place for this post but…

I’m having two issues related to removing the index.php from the urls in my app ...
I have followed the instructions from the user guide almost exactly. in fact my .htaccess is simply..

RewriteEngine on
RewriteCond
$1 !^(index\.php|public|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

The first issue only shows on the root page of my site… ( http://semantalyzr.com/ )

If I have

$config['index_page'] = "";

 
I get these notices/errors only on my root page semantalyzr.com/ (actually this is now happening for me whether I have this empty or “index.php”) (EDIT: This was fixed by making my .htaccess empty)

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 0

Filename: libraries/Router.php

Line Number: 197
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 0

Filename: libraries/Router.php

Line Number: 203
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 0

Filename: libraries/Router.php

Line Number: 206


The second issues is with the .htaccess file itself I believe…

for a certain type of page on that site you will get a 404 error if you leave out the index.php, (ex. http://semantalyzr.com/page/analysis/http://www.time.com/time/nation/article/0,8599,1858933,00.html?xid=rss-topstories )

I believe this is completely due to the urlencoding in the url conflicting somehow with the .htaccess rewrite rules because if I add the index.php to the url it works fine…

(ex. http://semantalyzr.com/index.php/page/analysis/http://www.time.com/time/nation/article/0,8599,1858933,00.html?xid=rss-topstories )


Currently I have index.php enabled because everything seems to work fine this way… but I would like to remove it ASAP.

Thanks in advance!

 Signature 

Wright Labs on Twitter

Profile
 
 
Posted: 21 November 2008 02:39 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  560
Joined  02-08-2007

Try

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

Its simple and fits my needs. Lets start there.

 Signature 

you’ve got that sexy Canadian thing working for you… - Derek Allard


EkJobs.ca | Clever Andy | http://DearIE6.com | twessage!
http://twitter.com/thatleeguy

Profile
 
 
Posted: 21 November 2008 04:50 AM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2274
Joined  07-27-2006

CI Lee. Really!? Try? Yes. Try this. Cut. Paste. Try. That’s what programming is now. Cut. Paste. Cross. Fin. Gers. Tr. Y.

 Signature 

Check out the Template Library
Oh yeah, I tweet, too.

Profile
 
 
Posted: 21 November 2008 05:14 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  12
Joined  10-06-2008

Thanks for the replies!

I pretty much fixed the first problem, and I have somewhat of a work around for the second problem.

I won’t bother with all the details but basically the root of the problems was in the .htaccess file.

I removed the “negative” approach “!^(index\.php|public|robots\.txt)” and did something different and it works now.

Thanks for the feedback!

 Signature 

Wright Labs on Twitter

Profile
 
 
Posted: 03 December 2008 11:38 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Avatar
Total Posts:  20
Joined  05-15-2007

Perhaps someone should update the User Guide? I ran into the exact same problem using the provided .htaccess code from the guide.

Profile
 
 
Posted: 04 December 2008 05:50 PM   [ Ignore ]   [ # 5 ]  
Summer Student
Avatar
Total Posts:  30
Joined  11-04-2008

It would be nice to see what were the changes that you made to the .htacces file I’m trying to change this in one of my app. I have search the forum but did to find a clear answer and I can see that a lot of people had issues with this.

 Signature 

The Lord is my programmer….

Profile
 
 
Posted: 04 December 2008 05:54 PM   [ Ignore ]   [ # 6 ]  
Summer Student
Avatar
Total Posts:  20
Joined  05-15-2007

alejandra -

Sorry! Here’s the .htaccess I used:

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

Thanks to CI Lee above for this!

Profile
 
 
Posted: 09 December 2008 05:52 PM   [ Ignore ]   [ # 7 ]  
Summer Student
Avatar
Total Posts:  30
Joined  11-04-2008
Mark Drzycimski - 04 December 2008 05:54 PM

alejandra -

Sorry! Here’s the .htaccess I used:

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

Thanks to CI Lee above for this!


I place this in a .htacces file and it did not work then I try

<IfModule mod_rewrite.c>
    
RewriteEngine On

    
# If the request doesn't start with any of the below
    
RewriteCond $1 !^(images|static|index\.php|favicon\.ico|robots\.txt) [NC]

    
# Prepend index.php internally
    
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

and my home page lost all the images and css file.

I’m trying this for the first what can I do, it seems like there is no clear way to do this.

 Signature 

The Lord is my programmer….

Profile
 
 
Posted: 15 January 2009 03:40 PM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  3
Joined  11-03-2008

I started having this same problem after switching from PHP4 to PHP5.

The problem with the above .htaccess “solution” is that it loosens the security of the site.  The original .htaccess (and the one that I use):

RewriteEngine on
RewriteCond
$1 !^(index\.php|public|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

has the advantage of preventing access to other files that are not listed in the RewriteCond rule.  And I like that extra security.  The .htaccess solution:

RewriteEngine on
RewriteCond
%{REQUEST_FILENAME} !-f
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteRule
^(.*)$ /index.php/$1 [L]

works to remove the “Undefined offset” warnings, but it also allows unrestricted access to other files that you might not want to allow.  So be really sure you understand what you are doing in .htaccess before you just blindly implement a recommended “solution”.

I decided to focus on the original cause of the error messages, rather than messing with .htaccess changes.

The “Undefined offset: 0” errors in the Router.php file are not really “errors”.  They are “Notices”.  When you access an undefined offset, PHP will return a null value, but will flag this with a “notice error”.  If your PHP.INI file is set up to report all “errors”, then you will get these messages.  However, in your PHP.INI file, you can set:

error_reporting =  E_ALL & ~E_NOTICE

and this will suppress the display of “notice errors”.  However, in the PHP5 CGI version, there is a bug that will still display errors on your web page, even if the “display_errors=Off” (see http://bugs.php.net/bug.php?id=44729).  So even changing the error_reporting option wasn’t working for me on my server.

So some people will see these Notice messages, while others might not, depending upon their error_reporting settings for PHP.

I finally decided to fix the code in the Router.php file for good.  It really isn’t hard, and the Code Igniter developers should really add this fix to the next release:

Edit your Router.php file, and then find the “_validate_request” function (line 196 for me).  At the beginning of this function, add this:

if (count($segments) == 0) $segments[0] = '';

I have seen some other solutions to this that do not work properly.  This is a very simple solution…if the array is empty, we just set the $segment[0] value to a null string.  This is what PHP is going to use anyway (after issuing the Notice error), so this just avoids the error/warning in the first place.  Simple and easy.

This fixed my site on PHP5, so hopefully this will help others.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 77566 Total Logged-in Users: 12
Total Topics: 101557 Total Anonymous Users: 2
Total Replies: 544401 Total Guests: 213
Total Posts: 645958    
Members ( View Memberlist )
Newest Members:  tnealsemperjrawhallshiusbozzlynobluffkatiejameshsmith101dddougalcamping