简体   繁体   中英

Codeigniter page loads on localhost but 404's on server

If I go to:

http://localhost/entry

I see my test page. If I go to:

http://examplesite.com/entry

I get a 404 page. And I don't mean the Codeigniter 404 page but the default apache one. The code bases are identical.

The homepage works fine but any inner pages 404. This is the contents of my root .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Removes access to the system folder by users. Additionally this will allow you to create a System.php controller, 'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    # When your application folder isn't in the system folder. This snippet prevents user access to the application folder. Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    # Checks to see if the user is attempting to access a valid file, such as an image or css document, if this isn't true it sends the request to index.php.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

Mod rewrite is enabled on the server verified with phpinfo(). Am I missing something?

When you see Apache's 404 status page instead of CodeIgniter's 404 , mod_rewrite is not active.

phpinfo only tells you, if a module is loaded, not if it's configured properly. You can check reliably, if mod_rewrite is active, by adding garbage to your .htaccess inside <IfModule mod_rewrite.c>...</IfModule> . When it is active, you will get a 500 server error.

To use mod_rewrite in .htaccess files, AllowOverride and Options must be set for the appropriate directory, eg

AllowOverride FileInfo
Options +FollowSymLinks

or even

AllowOverride All # default if <= 2.3.8
Options All # this is the default

Unrelated, but %{REQUEST_URI} starts with a slash, so the first two rules (with these RewriteCond s) will never match.

Did you check if the site's base url is set to your local address, if you installed CI on your live site, then chances are your base url is set to that URL. Try verifying it in the config file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM