Welcome Guest, Not a member yet? Register   Sign In
Issues removing index.php from my urls
#1

[eluser]jwright[/eluser]
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..

Code:
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
Code:
$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)

Quote: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/htt...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/an...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!
#2

[eluser]CI Lee[/eluser]
Try

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

Its simple and fits my needs. Lets start there.
#3

[eluser]Colin Williams[/eluser]
CI Lee. Really!? Try? Yes. Try this. Cut. Paste. Try. That's what programming is now. Cut. Paste. Cross. Fin. Gers. Tr. Y.
#4

[eluser]jwright[/eluser]
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!
#5

[eluser]Mark Drzycimski[/eluser]
Perhaps someone should update the User Guide? I ran into the exact same problem using the provided .htaccess code from the guide.
#6

[eluser]alejandra[/eluser]
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.
#7

[eluser]Mark Drzycimski[/eluser]
alejandra -

Sorry! Here's the .htaccess I used:

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

Thanks to CI Lee above for this!
#8

[eluser]alejandra[/eluser]
[quote author="Mark Drzycimski" date="1228452877"]alejandra -

Sorry! Here's the .htaccess I used:

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

Thanks to CI Lee above for this![/quote]


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

Code:
<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.
#9

[eluser]Zugg[/eluser]
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):
Code:
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:
Code:
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:
Code:
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.
#10

[eluser]Unknown[/eluser]
I use :
Code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
on my Windows machine and it's work properly
but why I can't do the same think on my Linux machine, i've make sure both are has rewrite module enabled.

oh, one point that make me litle confused is, my local wordpress installations are using same .htaccess rules and it work fine on my Linux.

any solution?




Theme © iAndrew 2016 - Forum software by © MyBB