Welcome Guest, Not a member yet? Register   Sign In
Remove index.php without setting $config['index_page'] to empty string [SOLVED]
#1

[eluser]cseguin[/eluser]
Hi all,

I'm working on a app that is behaving correctly on the hosting but I'm not able to replicate this behaviour locally.

Let me explain:

Without touching anything in the code

Code:
http://127.0.0.1/item/2

returns a 404 and...

Code:
http://127.0.0.1/index.php/item/2

works fine

On the hosting

Code:
http://www.onlineshop.com/item/2

works fine.

The question is, why? Why does it work fine on the server and not in my machine?

in config.php

Code:
$config['base_url']    = "http://zeus/shoponline";
$config['index_page'] = "index.php";

here I have made the following modification:

Code:
$config['base_url']    = "http://127.0.0.1";

and the .htaccess file looks like this:

Code:
RewriteEngine On
RewriteBase /

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


# BEGIN Compress text files
<IfModule mod_deflate.c>
  <FilesMatch "\.(css|js|x?html?|php)$">
    SetOutputFilter DEFLATE
  </FilesMatch>
</IfModule>
# END Compress text files

# BEGIN Expire headers
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
  ExpiresByType text/html "access plus 600 seconds"
  ExpiresByType application/xhtml+xml "access plus 600 seconds"
</IfModule>
# END Expire headers

# BEGIN Cache-Control Headers
<IfModule mod_headers.c>
  <FilesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </FilesMatch>
  <FilesMatch "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </FilesMatch>
  <FilesMatch "\.(js)$">
    Header set Cache-Control "max-age=216000, private"
  </FilesMatch>
  <FilesMatch "\.(x?html?|php)$">
    Header set Cache-Control "max-age=600, private, must-revalidate"
  </FilesMatch>
</IfModule>
# END Cache-Control Headers

# BEGIN Turn ETags Off
<IfModule mod_headers.c>
  Header unset ETag
</IfModule>
FileETag None
# END Turn ETags Off

# BEGIN Remove Last-Modified Header
<IfModule mod_headers.c>
  Header unset Last-Modified
</IfModule>
# END Remove Last-Modified Header

I've through all docs available about the subject and always mention to set index_page to empty string for this to work.

Obviously there has to be another way. Does anyone know how is it done?

Thanks.
#2

[eluser]bretticus[/eluser]
Do your config.php files match with respect to:

Code:
$config['index_page'] = "index.php";

...?

Have you tried removing index.php:

Code:
$config['index_page'] = "";

...per instructions?
#3

[eluser]cseguin[/eluser]
Hi bretticus,

thanks so much for replying.

Well I have read your other post about the subject, so yes I have tried

Code:
$config['index_page'] = "";

but with no success.

The curious thing is that the code in the server as it is right now

Code:
$config['index_page'] = "index.php";

does work without showing index.php on the url whereas in my machine does not work at all.

It does not matter if I keep the variable as it is now or if I set it to "". I always get a 404 error. Whenever I click on a link from the home page I get a 404 and index.php does not appear in the url.

One thing, I do not get the error when I enter into the site's home page. I get the error from there on.

However, if I get the 404 error and then manually I modify the url
Code:
http://127.0.0.1/item/2


to...

Code:
http://127.0.0.1/index.php/item/2

then it works fine.

any ideas?

regards
#4

[eluser]bretticus[/eluser]
The following config item:

Code:
$config['index_page'] = "index.php";

...probably just facilitates calls to base_url() and anchor() etc.. Because mod_rewrite is rewriting URLs internally, the config change shouldn't be a factor in getting 404 errors.

Are you absolutely certain you have mod rewrite enabled on your local machine? You can check with phpinfo().
#5

[eluser]cseguin[/eluser]
Hello again bretticus,

I have checked the mod_rewrite as you said. Not sure if is enable, what I'm sure is that is loaded.

After going through all the info phpInfo() returns I've found:

In Configuration - apache2handler -> Loaded Modules -> mod_rewrite


In my httpd.conf (apache 2.0):

Code:
LoadModule rewrite_module libexec/apache2/mod_rewrite.so

is uncommented.

So for what I ve read I assume that is enabled.

any more ideas?
#6

[eluser]bretticus[/eluser]
Yep, apache has it loaded.

Is your .htaccess file that you posted above in the same folder as index.php?
#7

[eluser]bretticus[/eluser]
You might try adding a ? to your rewrite:

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

By default, uri_protocol is set to "auto" in config.php:

Code:
$config['uri_protocol']    = "AUTO";

So it works differently on different hosts and configurations. :\
#8

[eluser]cseguin[/eluser]
yes, both are at root level (i.e. /Library/WebServer/Documents/) together with system
#9

[eluser]bretticus[/eluser]
[quote author="cseguin" date="1280958815"]yes, both are at root level (i.e. /Library/WebServer/Documents/) together with system[/quote]

Both?
#10

[eluser]bretticus[/eluser]
[quote author="bretticus" date="1280958932"][quote author="cseguin" date="1280958815"]yes, both are at root level (i.e. /Library/WebServer/Documents/) together with system[/quote]

Both?[/quote]

Sorry, I know you mean both the index.php file and the .htaccess file. Nevermind.

Try my last suggestion.




Theme © iAndrew 2016 - Forum software by © MyBB