CodeIgniter .htaccess rewrite not working on Live Server - php

I have a little problem with Code Igniter project, I have a .htaccess file to rewrite the index.php. It works great if I put my projects on Local Server. I am using WAMP Server. But now I have uploaded it on Live Server for example (godaddy,00webhost). And it is showing error :
404 Page Not Found.The page you requested was not found.
My .htaccess is here :
RewriteEngine on
RewriteBase /directory_name/
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favico​​n\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
and my config.php setting is here:
$config['base_url'] = 'http://example.com/directory/' ;
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
I have tried many solutions on web but not enough lucky to find one who helps me. I am stuck since 3 days. Anyone Help me.

If you are trying to host the website in a subfolder, make sure you enter the correct info in your htaccess and config:
Change RewriteBase /directory_name/in htaccess to RewriteBase /ci_foam/
Change $config['base_url'] = 'http://example.com/directory/' in your config to $config['base_url'] = 'http://php0713061.herobo.com/ci_foam/'
You always need to make sure these values matches your current server setup.

Related

Codeigniter base_url in plesk

Recently I uploaded a website which created using codeigniter framework into plesk. Inside the c-panal I changed the document root into httpdocs/public_html/cliftonhotel.ae, and I uploaded the files using FTP into the same. I changed the base_url into
$config['base_url'] = 'http://cliftonhotel.ae/';
The problem is if I enter the web address it loads fine(The home page), but the other menus are not working, they shows a 404 page not found error.
[http://cliftonhotel.ae/][1]
this is the site. What is the solution, thankyou.
Do some changes, hope it's work
// .htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
// config.php
$config['index_page'] = ' ';
It seems that the links you have created are missing index.php
For example: http://cliftonhotel.ae/index.php/home/about works
but http://cliftonhotel.ae/home/about does not.
So you have to either change the links or edit your .htaccess for url rewriting

Previously working .htaccess in codeigniter 3.1.2 not working after trying prerender.io

I was using the following configuration in .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
It was working fine and the home page was displayed as soon as I entered www.my-site.com.
Then I tried to implement prerender.io in codeigniter using the .htaccess file provided in this link: https://gist.github.com/thoop/8072354. The new .htaccess file is as follows:
<IfModule mod_headers.c>
RequestHeader set X-Prerender-Token "MY_TOKEN"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
<IfModule mod_proxy_http.c>
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff))(.*) http://service.prerender.io/http://www.my-site.com/$2 [P,L]
</IfModule>
</IfModule>
I also tried the comment of #benceg just below the post but this also did not work:
RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent))(index\.php)?(.*) http://service.prerender.io/%{REQUEST_SCHEME}://%{HTTP_HOST}/$3 [P,L]
The above .htaccess file did not work, and worse yet, when I replaced my previous (the one mentioned at the beginning) fully working .htaccess file back, it was also not working.
When I entered www.my-site.com, it showed me “Website under construction”.
Then I tried www.my-site.com/mycontroller and, to my surprise, my home page was being shown. This clearly indicates that my .htaccess file (which was previously fully working) is now “partially” working.
But again when I tried www.my-site.com, it showed “Website under construction”.
Some codeigniter configurations that I currently have:
$config['base_url'] = 'http://www.my-site.com/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$route['default_controller'] = 'mycontroller';
I am using Bluehost Shared Hosting service and I know they support mod-rewrite.
I do not want prerender.io anymore. What did I enable or disable while trying the new (prerender.io version) .htaccess? What can I do to get my fully working "previous state" back?
I tried to search the net for similar issues but did not find anything specific to my problem.
Update:
I tried using the first (previously working) .htaccess file on local lampp server and it is working as usual but it is still not working on Bluehost server.
Update 2:
An interesting finding I made today. When I am checking my site's (address: northernschoolofmusic.com.cp-in-13.webhostbox.net) speed on Google, the page is being rendered correctly. But when I am accessing the above mentioned link in a browser I am instantly redirected to http://northernschoolofmusic.com.cp-in-13.webhostbox.net/cgi-sys/defaultwebpage.cgi .
The problem was finally the internet connexion. The Internet Provider may have saved the DNS incorrectly and redirected to a wrong cached page.
Changing the browser or the connexion provider was the solution !
use this htaccess -
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
and config settings should be like that
$config['base_url'] = 'http://www.my-site.com/';
$config['index_page'] = '';
please follow this it will work...

CodeIgniter upgrade from 2.2.0 to 3.0.x: Only the default controller is loading

I don't usually post messages on the web to get help but I feel that I have tried everything and I am stuck.
I wanted to upgrade CodeIgniter from version 2.2 to version 3.0.3 (I tried v3.0.2 too) and I followed the corresponding guide on codeigniter.com. But now, only the default controller is loaded, no matter the url.
I have searched on the web and I have found out that it could come from:
the htaccess
the application/config/config file
the application/config/routes file
the new Ucfirst rule for the filenames (controllers, models...)
But I still don't have the solution...
The files in "applications/controllers" are all Ucfirst.
Everything was working fine before (with version 2.2), so WAMP should be correctly configured (mod_rewrite enabled etc...). Moreover, I have tried and succesfully loaded a clean instance of CodeIgniter 3.
Models, Controllers and Views are loaded correctly, I can change my default controller and it will load the correct view (with requests done by controllers and models). But it only loads the default controller, no matter what the url is (in the browser). Even if it does not exist, I never have the 404 page. Except if I specify an incorrect "default_controller" (in the file "routes.php").
It has to be a routing issue...
Here is some of the tests I have done:
Table of tests
Here is my htaccess file (I have tried other ones on the web too, the result is the same):
RewriteEngine On
#Checks to see if the user is attempting to access a valid file,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Enable access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
Here is my "application/config/routes" file:
$route['default_controller'] = 'dashboard';
$route['404_override'] = 'auth/e404';
$route['translate_uri_dashes'] = FALSE;
Any help would be appreciated :-)
Thank you !
SOLUTION
$config['enable_query_strings'] was set to "TRUE" in the file "application/config/config.php". Setting it to "FALSE" solved the issue. So simple...
try putting the index method in the routes, for example instead of this
$route['blog'] = 'blog';
try this
$route['blog'] = 'blog/index';
and if that doesn't work, can you confirm you have set the correct base url in application/config/config.php ?
In codeigniter 3 wamp
I use this htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
With your error 404 over ride can not be in sub folder.
Change
$route['404_override'] = 'auth/e404';
To
$route['404_override'] = 'e404';
And on config.php
$config['base_url'] = 'http://localhost/your_project/';
// You can leave base url blank but not recommended because when you try to submit forms make cause issue.
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

CodeIgniter cannot find anything other than default_controller

I am very new to CodeIgniter so obviously I have problem with the most basic things. I have recently tried to implement a website on local environment. I am using WAMP and the website is in www/public_html. Now the website is working on my localhost but if I try to navigate to any other page from the default (default_controler) it returns not found like
The requested URL /public_html/signin/login/ was not found on this server
I assumed that the website was designed to resolve its path related problems by itself. I am obviously missing something very basic.
I have changed the base_url in the config.php file by the way.
$config['base_url'] = 'http://localhost/public_html/';
I have no clue where else the base_url are or where to change it. Any help will greatly appreciated.
Zain
You are getting this problem because you don't have your .htaccess file configured correctly. At the document root in your .htaccess file you need the following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
In your config.php you will need to do
$config['index_page'] = '';
You also need to make sure you have mod_rewrite enabled
ther is a problem with your index.php. check this line
$config['index_page'] = 'index.php';
if it works u have to add an ht access file to remove index.php from ur url
there are a lot of code for .htaccess file on web try using one that suits you

CodeIgniter htaccess and URL rewrite issues

I have never used CodeIgniter before, let alone ANY php framework and I thought I would give it a try. Everything is going fine except I cannot seem to remove the index.php from the URL and still access my pages.
I have never used the MVC structure so I am learning as I go, so forgive me if I'm doing this wrong.
I am trying to access a view I created called 'about_page.php' by simply typing in localhost/ci/about but currently I can only access it by using localhost/ci/index.php/about
The controller for the page is: /application/controllers/about.php
The Model for the page is: /application/models/about_model.php
And the View for the page is: /application/views/about_page.php
I have searched for a solution to this issue, but haven't been able to find one. Here is where I have already searched:
CodeIgniter - removing index.php
Codeigniter - how to remove the index.php from url?
http://www.farinspace.com/codeigniter-htaccess-file/
CodeIgniter comes with a .htaccess file in the 'application' folder which contains only Allow Deny From All. So I created a new .htaccess file in the root directory, http://localhost/ci/.htaccess and added this code to it:
RewriteEngine On
RewriteBase /ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
When the .htaccess file is in the root directory I get a 500 Internal Server Error. When I copy the exact same file into the applications folder the 500 error goes away, but I still cannot access the about page by using localhost/ci/about
I have already changed $config['index_page'] = 'index.php'; to $config['index_page'] = ''; AND I tried changing $config['uri_protocol'] = 'AUTO'; to $config['uri_protocol'] = 'REQUEST_URI'; but I am still getting the Internal Server Error.
I went into the httpd.conf file and uncommented the mod_rewrite.so module so I know mod_rewrite is active.
Does anyone have any ideas why this isn't working or how I can get this work? I know there are alot of questions on StackOverflow on this subject but I couldn't find one that answered my question.
Am I doing this right? Should I even be able to access the about page by visiting localhost/ci/about or do I have to create an 'about' directory in the 'application' directory?
There are 3 steps to remove index.php.
Make below changes in application/config.php file
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Make .htaccess file in your root directory using below code
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Enable the rewrite engine (if not already enabled)
i. First, initiate it with the following command:
a2enmod rewrite
ii. Edit the file /etc/apache2/sites-enabled/000-default
Change all AllowOverride None to AllowOverride All.
Note: In latest version you need to change in /etc/apache2/apache2.conf file
iii. Restart your server with the following command:
sudo /etc/init.d/apache2 restart
Your .htaccess is slightly off. Look at mine:
RewriteEngine On
RewriteBase /codeigniter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system)
RewriteRule ^(.*)$ /codeigniter/index.php?/$1 [L]
Notice "codeigniter" in two places.
after that, in your config:
base_url = "http://localhost/codeigniter"
index = ""
Change codeigniter to "ci" whereever appropriate
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dmizone_bkp
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system)
RewriteRule ^(.*)$ /dmizone_bkp/index.php?/$1 [L]
</IfModule>
This works for me
Move your .htaccess file to root folder (locate before application folder in my case)
RewriteEngine on
RewriteBase /yourProjectFolder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Mine config.php looks like this (application/config/config.php)
$config['base_url'] = "";
$config['index_page'] = "index.php";
$config['uri_protocol'] = "AUTO";
Let me know if its working for you guys too ! Cheers !
I am using something like this - codeigniter-htaccess-file, its a good article to begin with.
leave the .htaccess file in CI root dir
make sure that mod_rewrite is on
check for typos (ie. controller file/class name)
in /application/config/config.php set $config['index_page'] = "";
in /application/config/routes.php set your default controller $route['default_controller']="home";
If you are running clean installation of CI (2.1.3) there isn't really much that could be wrong.
2 config files
controller
.htaccess
mod_rewrite
read
Codeigniter .htaccess
redirect-index-php-in-codeigniter
For those users of wamp server, follow the first 2 steps of #Raul Chipad's solution then:
Click the wamp icon (normally in green), go to "Apache" > "Apache modules" > "rewrite_module". The "rewrite_module" should be ticked! And then it's the way to go!
if not working
$config['uri_protocol'] = 'AUTO';
change it to
$config['uri_protocol'] = 'PATH_INFO';
if not working change it to
$config['uri_protocol'] = 'QUERY_STRING';
if use this
$config['uri_protocol'] = 'ORIG_PATH_INFO';
with redirect or header location to url not in htaccess will not work you must add the url in htaccess to work
I had similar issue on Linux Ubuntu 14.
After constant 403 error messages in the browser and reading all answers here I could not figure out what was wrong.
Then I have reached for apache's error log, and finally got a hint that was a bit unexpected but perfectly logical.
the codeIgniter main folder had no X permission on folder rendering everything else unreadable by web server.
chmod ugo+x yourCodeIgniterFolder
fixed first problem. Killed 403 errors.
But then I started getting error 500.
Culprit was a wrong settings line in .htaccess
Then I started getting php errors.
Culprit was same problem as main folder no X flag for 'others' permission for inner folders in application and system folders.
My two cents for this question: READ Apache Error.log.
But, also be aware of security issues. CodeIgniter suggests moving application and system folder out of web space therefore changing permissions shall be taken with a great care if these folders remain in web space.
Another thing worth mentioning here is that I have unzipped downloaded CodeIgniter archive directly to the web space. Folder permissions are likely created straight from the archive. As given they are secure, but folder access issue (on unix like systems) is not mentioned in CodeIgniter manual https://codeigniter.com/user_guide/installation/index.html and perhaps it shall be mentioned there with guidelines on how to relax security for CodeIgniter to work while keeping security tight for the production system (some security hints are already there in the manual as mentioned beforehand).
Just add this in the .htaccess file:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
By default the below sits in the application folder, move it like suggested into the root dir.
leave the .htaccess file in CI root dir
Open the application/config/config.php file and make the changes given below,
set your base url by replacing the value of $config['base_url'], as
$config['base_url'] = 'http://localhost/YOUR_PROJECT_DIR_NAME';
make the $config['index_page'] configuration to empty as $config['index_page'] = '';
Create new .htaccess file in project root folder and use the given settings,
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|assets|images|js|css|uploads|favicon.png|favicon.ico|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Restart the server, open the project and you'll be good to go.

Categories