I have a problem on my DigitalOcean server. I am using Ubuntu. CodeIgniter returns to me 404 but on my localhost it is all fine. Here is my mod_rewrite
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /localhost/x/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'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
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Routes and Configurations are all fine.
I got the answer. Rename your controllers to have the first letter in upper-case.
example: main.php to Main.php
I don't know why, but it worked! Hope ths helps!
It looks to me like you forgot to enable mod_rewrite in the Apache .conf files use sudo a2enmod rewrite then sudo service apache2 restart to start
mod_rewrite.
See Digital Ocean tutorial for more details:
https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04
Related
I have .htaccess file like this in my app. (only a sample for security)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app_folder/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'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
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
in (Rewritebase /app_folder/) what will i put in the app_folder name if my app is in the server? should i put the hostname in the app_folder? for example
Rewritebase /http://example.com/
because my app_folder is now my webroot. I'm new in uploading my HMVC codeigniter setup in server using CentOS.
In Ubuntu(linux):
Run in terminal :
a2enmod rewrite
and then:
service apache2 restart
mod_rewrite will now be enabled!
In Windows(wamp)
You can manually edit the httpd.conf file
left click wampmanager -> Apache -> httpd.conf
This will open that file in notepad and you can locate the line
#LoadModule rewrite_module modules/mod_rewrite.so
and remove the comment symbol '#' to activate the module. Then save the file and restart Apache to activate this change.
I have integrated my codeigniter project with Ubuntu 14.04. It was giving me url not found errors after the default controller, which is login controller.
Please find following .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myapp/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'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
#Submitted by: Fabdrol
#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>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Ok you first need to enable mod_rewrite
sudo a2enmod rewrite
sudo service apache2 restart
then open apache conf file
sudo gedit /etc/apache2/apache2.conf
uncomment this line if it is commented
AccessFileName .htaccess
you need to change AllowOverride to All - note my root is var/www/html yours might be just var/www
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Restart apache and that should do the trick
sudo service apache2 restart
I used CodeIgniter for most of my projects a while back. I'm getting back into the swing of things and hitting some bumps. I'm now developing on Mac OSX Mavericks and using MAMP as my Apache server. Everything seems to be running okay but I can't get rid of the index.php in the URL the whole time. I have added in the .htaccess file into the root of the project. Here's the file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ez-recruits/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'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
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I'm not super clued up about how to make these files so generally I just get them from CodeIgniters website. I'm getting a 404 Error without the index.php in the URL and if I manually type it in, the page will load fine. Also, I was developing in Firefox and I was getting an error saying "Firefox could not understand the address" without the index.php in the URL. I do have mod_rewrite activated on the Apache server. I have removed index.php in my config file for the index page and I have set the base_url to
$config['base_url'] = 'localhost:8888/ez-recruits';
I did some research and found that changing the httpd.conf file helped someone else, so I changed the part of it to this:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
But it has changed nothing. Does anybody know what I could be doing wrong or if this is just a Mac problem? Also, with all of these configurations, will I struggle to develop alongside someone else who is developing on a Windows machine?
Thanks in advance.
Try this for your .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'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
#Submitted by: Fabdrol
#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 %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Also, you can leave $config['base_url'] blank, which makes life easier if you're working on multiple systems.
Hope this helps!
You need to use base_url and index_page in the config.php file
$config['base_url'] = 'http://yourlocalurl/';
$config['index_page'] = 'index.php';
Ensure the following helpers are loaded in config/autoload.php
$autoload['helper'] = array('url','file');
I'm trying to install CodeIgniter (I have Mac). I have no experience with Frameworks, but I've read a little about MVC. My goal is to get CodeIgnitor set up so I can use it.
so I download CodeIgniter, then in one tutorial I'm told the following: Copy the file to your server’s web root folder, usually /var/www/ !
In this tutorial: http://www.phpeveryday.com/articles/CodeIgniter-Introduction-to-CodeIgniter-Framework-P147.html
I am told to "Open your root web server" and put the folder inside.
What is the "root web server"? Is it my htdocs? Where am I supposed to put this folder?
I put the folder into my HTDOCS folder because thats where all PHP files go, but I'm not sure if I did it right.
Please, install the easiest thing in the world XAMPP
find folder xampp/htdocs (desired web root folder) and create folder in it (project name), unzip/unrar/un7z CI in there so your folder structure is going to be
xampp/htdocs/project_name/application
/system
/index.php
Open up project_name/application/config and go thru all files see them one by one so you know what CI can and can not do it is well explained inside each file what every setting does.
If you are new to CI follow this video tutorial
if you are looking for good .htaccess file grab this one and change for whatever you need
note: this file should be in /project_name
note2: also in config/config.php set index_page to $config['index_page'] = '';
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /<your project name>
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'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
#Submitted by: Fabdrol
#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>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
after changing .htaccess and config/config.php your urls are "nice"
localhost/project_name/controller/method/parameter1/parameter2
finally: it is CodeIgniter not CodeIgnitor
I get an server 500 error with this htaccesss file in my xampp enviorment.
My $config['index_page'] variable is set to ''
C:/xampp/htdocs/codeigniter_test/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /codeigniter_test/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'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
#Submitted by: Fabdrol
#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>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
So if I go to localhost/codeigniter_test/site/home now I get this server 500 error.
site = controller and home = function in the site controller which loads up the home view
Also localhost/codeigniter_test/site/about is not working for me.
I don't get any 404 page so this means my mod_rewrite module is enabled.
I also checked this in my httpd.conf file.
Apache logs says:
[core:alert] [pid 1484:tid 512] [client 127.0.0.1:3870] C:/xampp/htdocs/codeigniter_test/.htaccess:
Edit: So I just removed the entire IF part.
Now localhost/codeigniter_test/ works.
But if I go to localhost/codeigniter_test/site/home it doesnt work and I get an 404 page.
Edit2: I change AllowOverride None to AllowOverride All in my httpd conf file.
Now I get a 403 error when I go to: localhost/codeigniter_test/site/home/
"The requested URL /codeigniter_test/site/home was not found on this server."
I got similar issue, basically, it's a permission issue:
try granting 755 permission on the folders and subfolders
chmod 755 *
chmod 755 */*
chmod 755 */*/*
chmod 755 */*/*/*
chmod 755 */*/*/*/*
I only have this in my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Hope that helps