.htaccess is not working on the server - .htaccess

I've been installing codeigniter on my server. I use my htaccess to remove index.php from the url. Application is working fine when on my pc. I use XAMPP.
but when i uploaded into the server it only shown the homepage, i cannot access other controller without index.php
Anyway i put all the codeigniter files in root not under the directory.
PFB my .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]
#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've been configure on the config files.
$config['base_url'] = 'http://114.6.xx.xxx/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
I've been check the module rewrite is Active, with this code.
<?php
if(!function_exists('apache_get_modules') ){ phpinfo(); exit; }
$res = 'Module Unavailable';
if(in_array('mod_rewrite',apache_get_modules()))
$res = 'Module Available';
?>
<html>
<head>
<title>A mod_rewrite availability check !</title></head>
<body>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $res"; ?></p>
</body>
</html>
below is the result of above code.
Apache/2.4.6 (CentOS) PHP/5.4.16
mod_rewrite Module Available

Related

2 codeigniter applications & htaccess

I had a codeigniter proyect working in windows with XAMPP and now I was moving it to my RaspberryPi:
Apache/2.2.22 (Debian)
PHP 5.4.4-14+deb7u5
mysql Ver 14.14 Distrib 5.5.31
I have two codeignitir aplications (principal and panel) with this estructure
/ -> (apache root folder)
/appname/admin
/admin/application/ -> (codeigniter application to panel)
/appname/application/ -> (codeigniter application to public)
Now I can't access to admin controllers and I think is because .htaccess. I get this in some url:
my.domain/appname -> codeigniter welcome for public (this part is empty so I think is OK)
my.domain/appname/admin/login.html -> Not Found. The requested URL /mydomain/admin/login was not found on this server.
my.domain/appname/admin/index.php?controller=admin -> 404 Page Not Found (codeigniter style)
my.domain/appname/admin/hello.html -> hello (a dummy file I put to try, works ok)
In my codeigniter panel proyect I have
$config['base_url'] = 'http://my.domain/myapp/admin/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '.html';
I think it's all about .htaccess but I don't understand them. How many files I need? What folders?
I had this .htaccess in my /appname & /appname/panel before
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /appname #to panel /appname/panel
#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
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule .* index.php/$0 [PT,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>
I think RewriteEngine on is activated in my apache2.
I found solution by .htaccess inside admin's folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /appname/admin
#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 'appname' to your applications folder name.
RewriteCond %{REQUEST_URI} ^appname.*
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>
CodeIgniter multiple applications htaccess
<IfModule authz_core_module>
RewriteEngine on
RewriteRule ^([a-z0-9_-]+)\.html$ index.php/page/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|asset|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Server ignoring subdirectory htaccess file, going straight to root htaccess

I have an application that utilizes Codeigniter and SLIR (Smart Lencioni Image Resizer https://github.com/lencioni/SLIR). SLIR allows you to resize images using an intuitive URI structure. For example:
<img src="/slir/w100-h100/path/to/image.jpg"/>
This would resize the image to fit 100px * 100px. For whatever reason when I try to view a resized image, (eg. http://a2op03.com/slir/w300-h90/images/content/franchise-opportunities-badge.png) I am getting a 404 error generated by Codeigniter. I have verified the following:
http://a2op03.com/images/content/franchise-opportunities-badge.png does exist.
According to the host mod_rewrite is setup properly and working.
GD Library (for SLIR) is setup and enabled
According to SLIR, everything is setup properly (http://a2op03.com/slir/install/)
The Codeigniter [root] htaccess file looks like this:
<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>
and the htaccess file in /slir/ looks like this:
# Prevent other scripts from interfering with SLIR
php_value auto_prepend_file none
php_value auto_append_file none
# Pretty URLs
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=40]
RewriteRule . index.php [L]
</IfModule>
# Prevent viewing of the error log file in its default location
<Files slir-error-log>
Order Deny,Allow
Deny from All
</Files>
My initial suspicion was that mod_rewrite.c was not setup properly and therefore was not being processed by the SLIR htaccess and falling back on the root htaccess which is sending it to a 404. I'm hosting on a managed VPS via servint.net and have WHM with full access to the server. The host claims that mod_rerwrite should be working fine. I have this working flawlessly on another server, but I can't figure out why it's not working here. Any helps is appreciated!
I figured it out! I just needed to add
RewriteBase /slir/
After
RewriteEngine On
In SLIR's htaccess file!

Getting rid of index in URL when using CodeIgniter and HTTPS

I've been working on a codeigniter application. When I first started developing it I used the following url structure:
http://somewebsite.com/application/login/
I changed the site to run over https
https://www.somewebsite.com/application/login/
The problem is any calls to the server only work like this.
https://www.somewebsite.com/application/index.php/login/
I want to get rid of the index.php. Any thoughts?
You need to have you .htaccess rewrite SSL properly. This is an .htaccess I use that works - although it FORCES SSL. Not sure if you want to do that:
<IfModule mod_rewrite.c>
RewriteEngine On
#Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R,L]
#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>
check and edit the application/config/config.php.
in that change the following line
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
just remove index.php and then it should work lust fine...

remove index.php of codeigniter subdomains

this is my directory:
-root
-CI
-application
-system
-sub-domain1 (codeigniter )
-application
-sub-domain2 (codeigniter )
-application
-www
-folder1
-folder2
.....
-folder10
-sub-domain1
-index.php (used for codeigniter)
-sub-domain2
-index.php (used for codeigniter)
-file1.php
-file2.php
-file3.php
.....
-file10.php
-index.php (used for codeigniter)
- .htaccess
in my application/config/config.php is:
$config['index_page'] = "";
I didn't have the sub-domain1 and sub-domain2 and I wanted to apply them now. I am using same system for all CIs. I used the following htaccess file and it works perfect.
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>
now when I add sub-domain1 and sub-domain2 I have problem with index.php. for main CI index.php is gone but for sub-domains I don't know how i can do that.
www.mydomain.com/folder1/... ok
www.mydomain.com/controler/function ok
www.sub-domain1.mydomain.com/index.php/controler/function ok
www.sub-domain1.mydomain.com/controler/function NOT ok
please help me.
thanks
You should be able to share the system directory across all of your CI installations, providing a central place for upgrades, and using less disk space.
Take a look in application/config/config.php
and the line: $config['index_page'] = "index.php";
should look like: $config['index_page'] = "";

Code Igniter - URL Rewrite

Hey, i'm trying to get a project to work, but i am having trouble with the rewrite module.
I'm running Wamp over Windows XP. I changed httpd.conf to change the root of localhost to:
DocumentRoot "C:/wamp/www/project/docroot/"
I have htaccess
RewriteEngine On
RewriteBase /
my Apache has the rewrite module Activated.
my base_url() in config.php is 'http://localhost/'
in routes.php i have:
$route['default_controller'] = "home";
$route['our-recipes'] = "recipes";
and more pairs
when i point the browser to http://localhost/ i get the homepage of my site, but when i click on any internal link like to 'our-recipes' it loads but i get the same homepage, with the new url on the location bar. if i try to access 'http://localhost/recipes' i get the same result.
this is my folder structure:
Can anyone please solve this for me??
Give this a shot (taken from the wiki)
<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>

Resources