I have written a CodeIgniter application and I want to use mod_rewrite to clean up my URL's. I have installed the CodeIgniter application in htdocs/ci-intro/
Here is my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/
#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>
I altered the config.php in CodeIgniter to the following:
$config['base_url'] = '';
$config['index_page'] = '';
Whenever I use my links to go to the about page I get a 404 message from CodeIgniter. The URL in my browser seems to be 'cleaned up' though (index.php is removed). This is the URL:
'http://localhost:8888/ci_intro/about'
Can anybody help me getting rid of the 404 error and actually directing the use to the about page?
OS: MAC OS X 10.8.2 (latest)
SERVER SOFTWARE: MAMP
PHP: 5.2.17
BROWSERS: Chrome & Safari (In both browsers this problem occurs)
Before reviewing your server configration, please try code below:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/
#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.*
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>
try this...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /Your_folder_Name/index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /Your_folder_Name/index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ Your_folder_Name/index.php?/$1 [L]
</IfModule>
Coincidentally I am using the same configuration like yours, and end up it didn't really work no matter how i change it.
So I gave up changing it and tried another simplest setting.
Try this out, it works for me!! :)
<IfModule mod_rewrite.c>
RewriteEngine on
# If the start of the URL doesn't match one of these...
RewriteCond $1 !^(index\.php|robots\.txt|assets|cache|images|uploads)
# Route through index.php
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{REQUEST_URI} ^system.*
probably isn't going to trigger, since REQUEST_URI starts with /. Try
RewriteCond %{REQUEST_URI} ^/system
Ditto for
RewriteCond %{REQUEST_URI} ^application.*
And does your system really want /index.php?/blah blah? It's going to expect a URL Query String after the ?.
Related
I'm trying to build a shopping cart locally using PHP & MySQL. My main directory for my site is /Library/WebServer/Documents. I tried to set it up so that I can access localhost/project without the index.php.
Here's my htaccess:
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
My config code (extracted, not the whole thing):
$config['base_url'] = 'http://localhost/project/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Apparently there's an error with this. Even though I managed to access localhost/project without index.php, I can't view pages generated by my controller code (ex. if I try to go to localhost/project/welcome I get this error message: 'The requested URL /project/welcome was not found on this server.' localhost/project/welcome should take me to the Welcome.php page under my controllers folder.
Here's a snapshot of the file structure
Can someone explain to me what's wrong with my code?
Do you mean without .php?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
OR
remove this DirectoryIndex index.php!
It sets the index.php behind the url
Use this .htaccess:
<IfModule mod_rewrite.c>
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>
RewriteEngine On
RewriteBase /path/learn_ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /path/learn_ci/$1 [L]
Above my .htaccess file how to configure it.
On your .htaccess file put below code.
RewriteEngine On
RewriteBase /path/learn_ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|asset|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
On your application/config/config.php Put below code
$config['base_url'] = 'http://yourdomain.com/';
$config['index_page'] = '';
It will be work for you.
Enjoy...!!! :)
This is what I've been using on most of my CodeIgniter projects, and never had issues.
You need to adjust your RewriteBase. It starts from the root of the web server /www/your_project would be changed to /your_project/ in the htaccess file.
Also, make sure you have mod_rewrite enabled.
How to enable mod_rewrite for Apache 2.2
CodeIgniter htaccess and URL rewrite issues
In addition, you need to remove the index.php from $config['index_page'] = 'index.php' located in config.php in your CodeIgniter installation.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /your_project/
#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 $1 !^(index\.php|img|font|css|temp|js|robots\.txt|favicon\.ico)
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>
this should be your htaccess file on the root folder of your project
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / yourproject
#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>
and you can remove the index.php from the config.php as: $config['index_page'] = '';
Hi i have problems in the url .. i think the htaccess code when i uploaded my file to the live website i notice that the error is thi -------------->No input file specified. here is my link to the website http://springrainglobal.com/movies_world/index.php/movies
here is my htaccess code
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|images|js|assets|css)
RewriteRule ^(.*)$ /movies_world/index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /movies_world/index.php?/$1 [L]
can anyone help me out on how to configure properly the htacces on live server?pls help
Your site is available under http://springrainglobal.com/movies_world/movies (leave the index.php), if that's what you're looking for.
This is the standard .htaccess I always use for CodeIgniter builds:
<IfModule mod_rewrite.c>
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>
If you change line 3 of that code to
RewriteBase /movies_world/
you should be set.
So far I have a fresh install of 2.1.3 and have placed an .htaccess file with:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
in the root directory, same level as application, system, etc.
Edited $config['index_page'] = 'index.php'; to
$config['index_page'] = ''; in application\config\config.php.
Turned on rewrite_module.
Restarted Apache.
But I still end up with a 404 even after trying all the solution, even those in related posts.
Hope this could help this is my htaccess and it works for me.
RewriteEngine On
RewriteBase /codeigniter/
#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
You need to modify your httpd.conf to enable mod_rewrite and make sure that your webroot directory has AllowOverride set to 'ALL'
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
use this it will work
Ok so i have this in my .httaccess
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]
and this in my config
$config['index_page'] = "";
which seems to allow me to do this
http://localhost/ci_example/site
instead of this..which is good so far
http://localhost/ci_example/index.php/site
but now when i try to visit my welcome controller with
http://localhost/ci_example/welcome
it redirects me to
http://localhost/
why the redirect and what can i do to stop that ....the welcome controller has this
function index()
{
$this->load->view('welcome_message');
}
Use RewriteBase
RewriteEngine On
RewriteBase /ci_example/
Methinks that your rewrite rule should be
RewriteRule ^(.*)$ /ci_example/index.php/$1 [L,QSA]
I use this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /CodeIgniter/
#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>