I am struggling with this for hours now:
I have a codeigniter application in a sub folder in a godaddy hosting, lets say:
mydomain.com/myfolder/myapp/
I have this .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myfolder/myapp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]
</IfModule>
I read this doc: https://github.com/bcit-ci/CodeIgniter/wiki/Godaddy-Installation-Tips
but it won't help neither. Maybe because my ci app is in a subfolder?
How can I hide the index.php? and make it work with friendly urls?
Create a .htaccess file in you root directory (where codeigniter's index.php is) with this:
<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>
Then in your application/config/config.php :
$config['index_page'] = '';
This should solve the issue.
Use the following .htaccess for Godaddy hosting server. Please let us know if it works.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1
Have your /myfolder/myapp/.htaccess like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myfolder/myapp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
then in /myfolder/myapp/application/config/config.php you need to have this config:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
I'm surprised nobody wrote that you're supposed to put
Options +FollowSymlinks
at the beginning of your .htaccess file, for a GoDaddy hosted website.
Related
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'] = '';
I have my project developed in CodeIgniter which works perfect on XAMPP Server but Not working on WAMP server.
I've changed
$config['index_page'] = 'index.php'; to $config['index_page'] = '';
and .htaccess I've
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Homepage of website appears properly. But no link is working whenever I click on any link wamp server homepage appears in French version.
Project run properly on WAMP only if there is index.php in URL.
e.g.
http://localhost/codeigniter/welcome/view (This link doesn't work)
http://localhost/codeigniter/index.php/welcome/view (Links works properly)
Try this one, it's working everywhere :
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L]
Enable the mod_rewrite in your httpd.conf file
In my case I have installed WAMP on local disk C
to find httpd file just navigate to C:\wamp\bin\apache\apache2.2.6\conf
open httpd.conf file with notepad editor then find the line below:
#LoadModule rewrite_module modules/mod_rewrite.so
and uncomment it
save the file and restart Apache for the new setting to take effect.
try this
RewriteEngine On //missed this
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
check RewriteBase in .htaccess file.
it would be like below
RewriteBase /your project folder name/
copy below code and paste it in your .htaccess file
<IfModule mod_rewrite.c>
Options +FollowSymlinks
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]
#RewriteRule ^page/(.*)$ index.php?/#$1 [R=301,L,NE]
# 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;
hope it will help you. and check one thing i.e your url. if there is any ~ symbol then .htaccess file will be different. otherwise the above code will work. Thanks.
I install codeigniter and start to write some code on it.First i want to remove index.php and make some research about it.I remove it with a small htaccess code below,
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|robots\.txt)
RewriteRule ^(.*)$ /pasaj/index.php/$1 [L]
and then set my base_url in config.php as,
$config['base_url'] = 'http://localhost/pasaj/';
and then i decided to use base_url in form's actions
and wrote it like that(please look at action)
<form method="post" id="formSubmit" name="fSubmit" action=<?php base_url(); ?>"kayit/kayitOnay/">
but it did not work
and prints url like that
what i did all is not working
and i suspect from my htaccess file.I removed it. i use it for removing index.php in codeigniter default.
and set my new
base url like that necessarily
http://localhost/pasaj/index.php/
and do not change anything above form code
and it works.
Now, i want to still use this htaccess file in order to remove index.php but when htaccess file exists my base_url works wrongly . What might be the changes in htaccess file ?
try this
RewriteEngine on
RewriteBase /pasaj/
RewriteCond $1 !^(index\.php|images|css|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
My htaccess files on a local server looks like this:
For a Zend Framework web:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
For a CodeIgniter web:
RewriteEngine on
RewriteBase /pasaj/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
This is my standard htaccess file.
<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>
You may need to alter the rewrite base.
To remove index.php from url you can try the following.
Open config.php from system/application/config directory and replace
$config['index_page'] = “index.php” by $config['index_page'] = “”
Create a “.htaccess” file in the root of CodeIgniter directory and add the following lines.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
In some case the default setting for uri_protocol does not work properly. To solve this problem just replace
$config['uri_protocol'] = “AUTO” by $config['uri_protocol'] = “REQUEST_URI” from system/application/config/config.php
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>
I am an asp.net guy and this is the first time I've dealt with PHP.
Anyhow, I've struggled to migrate an existing site to a new server.
This site is using codeigniter.
When I call http://mydomain/admin
I get a 404 error!
But if I call:
http://mydomain/index.php/admin
it works!
I have placed an .htaccess file on the root:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|scripts|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I have set in the config.php:
$config['index_page'] = '';
My routes.php:
$route['default_controller'] = 'welcome';
$route['scaffolding_trigger'] = '';
I have no idea why it does not work. It must be something very simple I guess...
Thank you!
Did you look through this?:
http://codeigniter.com/wiki/mod_rewrite/
If not, try this one:
<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>
There used to be one from Jamie Rumbelow I used to use a bit, but it's not on his blog anymore... I'm used to nginx now though, so my favorite configuration won't work for you.
Your .htaccess file didn't work for me either. But it worked once I changed the rewrite rule to this :
RewriteRule ^(.*)$ index.php/$1 [L]
I just removed the slash at the beginning.
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
1º - Create an .htaccess file in the root you're CodeIgniter project.
2º - In the created .htaccess file put the code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
try adding RewriteBase / in .htaccess
$default_controller = "home";
$language_alias = array('gr','fr');
$controller_exceptions = array('signup');
$route['default_controller'] = $default_controller;
$route["^(".implode('|', $language_alias).")/(".implode('|', $controller_exceptions).")(.*)"] = '$2';
$route["^(".implode('|', $language_alias).")?/(.*)"] = $default_controller.'/$2';
$route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
foreach($language_alias as $language)
$route[$language] = $default_controller.'/index';
$route['404_override'] = '';