.htaccess Error in Codeigniter - .htaccess

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

Related

Codeigniter not working on godaddy server

I'm having issues with making codeigniter work on godaddy.
I tried various things but non seemed to work for me. Any help would be appreciated.
my htaccess file is like below:
RewriteEngine on
RewriteBase /code-igniter/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
and I already changed my config file:
$config['index_page'] = "index.php?";
$config['uri_protocol'] = 'REQUEST_URI';
Please help!!
<IfModule mod_rewrite.c>
RewriteEngine On
# If your page resides at
# http://www.example.com/code-igniter/
# then use
# RewriteBase /code-igniter/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
config/config.php
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

.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>

codeigniter 404 page not found in intranet deployment

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.

.htaccess file won't work

I'm running my app in XAMPP with CodeIgniter. I have a .htaccess file that will not necessitate me anymore of including index.php in url but it won't work.
The content of my .htaccess file is
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|crossdomain\.xml|captcha|images|assets|archive|css|js|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
I already set the all the directories with AllowOverride to All. I've already enabled mod_rewrite too but still my links won't work. Instead of going to the specified URL, it will go the XAMPP homepage.
Also in my config file, it looks like this:
$config['base_url'] = '';
$config['index_page'] = '';
Then in view:
a href="/signup"
Am I doing it right? Please help.
Try
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|monitor\.php|resources|test_gui|img|css|js|favicon\.ico|(.*)\.(png|js|jpg|swf|css|gif|ico|jpeg|scss)$)
RewriteRule ^(.*)$ index.php/$1 [L]

Resources