0

I created a site in PHP using CodeIgniter framework. When it was done, I edited routes.php file and added .htaccess file to eliminate /index.php/ part from URL.

Now, when I try to open it in localhost, it works fine, I can access http://localhost/mysite and get the landing page I wanted.

But, the problem is when I try to access the site on server, I get an error. So if I open something like http://mysite.com I get CodeIngniters' default 404 page. I can open all other pages if I specify their URL, like: http://mysite.com/about but when someone else opens the site, he gets an error and he doesn't know what to type in order to pass by that error.

What should I do to fix this? Thanks in advance.

EDIT: .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]
11
  • Can you show us what changes you made to each file mentioned? Commented Aug 1, 2013 at 11:35
  • I'm thinking the error is with the htaccess file specifically Commented Aug 1, 2013 at 11:36
  • did you change the contents of config.php ? Commented Aug 1, 2013 at 11:37
  • @Dale I edited the question with htaccess code @ VinodVT Yes, of course. Commented Aug 1, 2013 at 11:39
  • try removing the ? from index.php?/$1 Commented Aug 1, 2013 at 11:40

3 Answers 3

0

This .htaccess code works for me always, you can try this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

Comments

0

Your .htaccess does raise some concerns, you are attempting to pass the file location as a query string which may work in CodeIgniter but there is a better way of doing this.

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

Also, make sure in your config.php you have the following option set:

$config['uri_protocol'] = 'REQUEST_URI';

Good luck.

Comments

0

This .htaccess code works

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

And in config

$config['index_page'] = '';

14 Comments

No. It still gives me 404.
Give us your routes.php
And $config['base_url'] = 'YOUR WEBSITE';
base_url is set. Here's routes.php: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); $route['default_controller'] = "MasterKontroler"; $route['404_override'] = ''; $route['admin/(:any)']="AdminKontroler/$1"; $route['firma/(:any)'] = "FirmaKontroler/$1"; $route['kontakt'] = "MasterKontroler/kontaktirajteNas"; $route['login'] = "MasterKontroler/index"; $route['pretrazi'] = "MasterKontroler/pretrazi"; MasterKontroler has index() function and everything works in localhost. But landing page on server shows CI 404 page.
At end of routes try add $route["(.*)"] = 'MasterKontroler';
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.