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');
Related
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
I'm really starting to regret buying a domain at One.com
I have a simple CI project set up that works perfectly on localhost, but one.com isn't my friend. I can't seem to get mod_rewrite working. I don't even bother contacting support, because I'm getting the feeling that anyone who needs more than an index page isn't welcome there.
This is my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /luc/
#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]
#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
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|img|js|UberGallery|robots\.txt|css)
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>
And in CI config:
$config['base_url'] = '';//I have tried the full URI.
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; //I have tried REQUEST_URI as well.
luc is a subdomein of my domain, hence the RewriteBase in .htaccess.
In all my subfolders, I have an .htaccess file with deny from all.
This seems to be a one.com specific issue, so I hope there's someone experienced enough to spot an error in my setup.
What am I doing wrong?
Ive been using codeigniter CMS. It was working fine...until 4 days. I did play a bit with httpd.conf but it has .htaccess enabled and all so I am sure it might not be the problem . Whenever I click any page from home page of CMS it redirects to base_url.The login page of CMS appears fine and also logs into home page. The urls in the home page redirects to base URL.
Ive checked this question
CodeIgniter all the pages redirecting to home page?
Tried this solution by changing $config['uri_protocol'] = "AUTO" to options mentioned. But it doesn't seem to be the solution. My .htaccess file reads
DirectoryIndex index.php
<IfModule mod_rewrite.c>
#http://codeigniter.com/wiki/mod_rewrite
RewriteEngine On
RewriteBase /
#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>
Tried playing with config.php by changing base_url and all..but it doesn't seem to work. Any idea/help ?
I am new to CI and don't know much about rewrite rules. I was able to find htaccess rules from stackoverflow post which allows me to remove index.php from the URL. The ht access rules are as following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /siebeluigen/
#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>
But this doesn't work if I move my controllers to subfolder within the controller directly. for example
If I put my Application controller in following path
application/controllers/application.php
Then I can access it from URL
http://localhost/siebeluigen/application
But if my directory structure is
application/controllers/app/application.php
Then I get error with following url
http://localhost/siebeluigen/app/application
but it works like this
http://localhost/siebeluigen/index.php/app/application
So, I am pretty sure there is something in htaccess that I should be able to change to make it work.
Please help!!!
Update
My htaccess file was in the application folder instead of root. Moving the file to the folder were index.php is located solved the issue. I have marked the answer that is working.
Thanks...
This is my htaccess file that I use on ALL my projects:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# activate URL rewriting
RewriteEngine on
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(images|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt)
# but rewrite everything else
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.
ErrorDocument 404 index.php
</IfModule>
Then - also make sure that inside your config.php file
$config['index_page'] = '';
edit: you NEVER want to point someone to your application folder - you ALWAYS point them to your index.php - EVERYTHING goes through Index.php - and it does the re-routing to where it is needed.
This is the condition that is usually meant to redirect to application.php
RewriteCond %{REQUEST_URI} ^application.*
app/application doesn't match this condition. Try changing it to this:
RewriteCond %{REQUEST_URI} ^app/application.*
I have made a codeIgniter application. Its working oh so cool on my local, but when I deploy it to the main, all my pages are getting redirected to the home page.
I have the following directory structure:
---www
-----.htaccess
------codeIgniter (the application lives here).
My htaccess reads as follows
RewriteEngine on
RewriteCond $1 ^media
RewriteRule ^(.*)$ codeIgnite/$1
RewriteCond $1 !^(index\.php|codeIgnite|images|robots\.txt)
RewriteRule ^(.*)$ codeIgnite/index.php/$1
And this is my config.php
$config['base_url'] = "http://localhost/codeIgnite/"; // or should it just be http://localhost/ ?
Is there some other config settings I need to change ? Please help.
My home page shows up just fine. Problem is with other pages. No matter what URL I give, I see my home page UI.
Setting the $config['uri_protocol'] = "ORIG_PATH_INFO", fixed the issue.
I've used the provided .htaccess from CodeIgniter and just set the RewriteBase to my subdirectory to get it to work properly.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /codeIgnite/
#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>
You should have to put the .htaccess in the CodeIgniter folder and also you have to modify the last line of your file to this
RewriteRule ^(.)$ /codeIgniter/index.php/$1 or
RewriteRule ^(.)$ /codeIgnite/index.php/$1
You dont have to do nothing in apache config only turn on the extension rewrite_module