codeigniter 404 page not found in intranet deployment - .htaccess

Please guide me what is the issue? All of my pages are showing 404 not found in intranet deployment, while main (home) page is viewing fine.
.htaccess
RewriteEngine On
RewriteBase /dna/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dna/index.php/$1 [L]
routes.php
$route['default_controller'] = "home";
$route['404_override'] = 'error/index';
$route['pages/(:any)']="pages/view/$1";
$route['contact-us'] = 'contact_us/index';
$route['news'] = 'news/index';
I'll be grateful for any help or guidance.

Codeigniter automatically gets $config['base_url'] for your site, so you can leave that blank
Make sure you have mod_rewrite enabled.
then modify your .htaccess with this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^site_hostname.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
hope that solves it.

CodeIgniter have issues with subfolders.
Create new virtual host like dna.example.com
Remove dna/ from .htaccess and base_url settings.

RewriteEngine On
RewriteBase /dna/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
The above will work assuming you have set the correct $config['base_url'] in config
$config['base_url'] = "http://localhost/DNA/" or similar depending on your set-up.

Related

.htaccess not working on server

I have hosted a site as a sub folder like "http://www.sitename.com/projectfoldername/".
Here it shows only the home page and when clicked on any menu it shows 404 error ,so i changed the the url by writing index.php before the controller name now the url has changed from this:
"http://www.sitename.com/projectfoldername/controller-name/function-name" to this: "http://www.sitename.com/projectfoldername/index.php/controller-name/function-name" then it shows the pages but worked locally only..
my htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
config.php
$config['base_url'] = 'http://www.sitename.com/projectfoldername/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
If you used Apache Web Server, active your mod_rewrite
On Ubuntu:
sudo a2enmod rewrite
On Window:
Open your httpd.conf and Find the line
#LoadModule rewrite_module modules/mod_rewrite.so and remove the hash ‘#’
Use RewriteBase /projectfoldername in your .htaccess file like so:
RewriteEngine On
RewriteBase /projectfoldername
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
try adding following in .htaccess, it might help you.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
#antroo ghosh , At first you have to know that which web server is using( Apache or IIS).
If you are using windows(IIS) server you can't use .htaccess, In IIS you have to use web.config instead of .htaccess.
For more details https://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/translate-htaccess-content-to-iis-webconfig
I hope this may helps you!

Removing index.php using .htaccess not working on codeigniter hostgator

Basically I want to remove index.php in my url.
I think my .htaccess is not working on Hostgator and I've already searched my problem on these .htaccess, codeigniter and hostgator.
This is my folder structure in hostgator
/cgi-bin /httpdocs
|---/application
|---/system
|---.htaccess
|---index.php
My .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
My config.php
$config['base_url'] = 'www.example.com'; // this is only an example because our website is confidential
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Edit: Sorry for being idiot. I contacted the Hostgator after I posted this question and try the answers below. They say that I'm
running on Windows server not Apache server so my .htaccess will
not work so I need to convert it to web.config. Sorry for those
wasted time to answer this question. Thank you
Edit: I mark #Deep Parekh's answer as correct as #David said that it worked properly
Generally i use this htaccess on Hostgator:
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Make sure you changed your config.php file:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
.htaccess will look :
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
</IfModule>
In codeiginator config:
$config['uri_protocol'] = 'AUTO';
If htaccess is not working then
Configure Apache mod_rewrite
a2enmod rewrite
Add the following code to /etc/apache2/sites-available/default
AllowOverride All
In config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
In .htacess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule
I think its possible to use the htaccess.
http://support.hostgator.com/articles/specialized-help/technical/apache-htaccess/how-to-edit-your-htaccess-file
Maybe try these htaccess. It works at my local project.
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_URI} !^(index\.php|\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) ./index.php [L]
This is works for me:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

GoDaddy + CodeIgniter + subdomain

I'm attempting to remove index.php using the CodeIgniter framework (hosted with GoDaddy - Linux), which is currently installed to: example.com/ci
I've already declared the base_url in application/config/config.php as http://example.com/ci/.
The following is my latest test input for .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
Keep in mind that the domain CI is installed under is not my hosting root. The actual path for the CI folder would be: root/mydomain/ci
After spending the better part of the day today trying a plethora of "solutions", I'm beginning to wonder if this is possible to do with GoDaddy at all, or perhaps my situation is somehow unique.
Any advice would be greatly appreciated!
EDIT: The closest I've come to fixing this issue is using the following .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /clone/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^index.php/(.*)$ [L]
</IfModule>
.. while setting my base_url to mydomain.com/clone/ (using http:// of course) and removing index.php from index_page. Navigating to mydomain.com/clone works fine but navigating to the two pages that are part of the software results in a 404 page.
An answer to your comment, you need to add a rewrite condition to access the sites/ directory. CodeIgniter is looking for sites in the controllers folder.
RewriteCond $1 !^(index\.php|sites)
You can also add the names of your resource folders like images/video etc.
Change this
In your config.php
$config['base_url'] = '';
$config['index_page'] = '';
then in .htaccess
RewriteEngine on
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
or else you can use your .htaccess too
EDIT 01
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

.htaccess Error in Codeigniter

I am new to Codeigniter I have put an .htaccess in root folder of codeigniter 2.1.3.
I have tried my .htaccess file on both xampp & wamp server but this is not removing my index.php.
I have also set
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
and here is my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|js|images|system\/plugins|robots\.txt|css\/)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
i dont know why this is not removing my index.php page from url.
help me!!
Open config.php make sure to change $config['uri_protocol']= 'REQUEST_URI';
and in place this code in .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|indexcp\.php?|resources|robots\.txt)
RewriteRule ^([A-Za-z0-9_/.-]+)$ index.php?/welcome/$1
That's all it works for me. Let me know if you are still facing any problem.
Check whether rewrite_module is configured as on
And try removing the condition from your code:
RewriteEngine on
RewriteCond $1 !^(index\.php|js|images|system\/plugins|robots\.txt|css\/)
RewriteRule ^(.*)$ index.php/$1 [L]
I used this code in my project it works for me,
.htaccess :-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
config.php :-
$config['index_page'] = '';
$config['base_url'] = 'http://www.example.com/';
I hope this will help you
Another sily problem that could be done is that the folder that contains the application is not 755.
For be more sure about what is the problem look your apache log file , in linux /var/log/apache/error.log

Codeigniter page not found

i've website built with CODEIGNITER working perfect on my local server but when i uploaded it on live it give me error 404 and after updating .htaccess with following code now its giving me 500 error
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /home/index.php?$1 [L]
any solutions...
This is an .htaccess rule so specify your RewriteBase as the manual says (you've read this of course). That's
RewriteBase /
for a DOCROOT/.htaccess and if your Codeigniter catachall script, index.php is in DOCROOT as well then the rule should be:
RewriteRule ^(.*)$ index.php/$1 [L]
this works for me
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
in config.php
$config['index_page'] = '';
and
$config['uri_protocol'] = 'AUTO';
hope it help

Resources