mod_rewrite CodeIgniter - .htaccess

Now URL for my website is for example: http://localhost/xxx/index.php/welcome/
I want to change this to: http://localhost/xxx/welcome/
My .htaccess file:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
My config.php file:
$config['base_url'] = 'http://localhost/xxx/';
$config['index_page'] = '';
But my new URL still doesn't work. What should I add there?

You can try the following mod_rewrite. It actually works and I saw this on one of the tutorials I watched here and here is the .htaccess.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /foldername/foldernameifapplicable/foldernameifapplicable
#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 do not recall all the changes made, but I followed the following tutorial and it did what you ask.
https://www.youtube.com/watch?v=I752ofYu7ag
htaccess looked like this
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>

Related

Codeigniter site was not working in live server

Can someone help me,
My site was working fine in staging server and I moved the site live server where I am getting HTTP ERROR 500.
My htaccess file is
<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>
The same htaccess file was there in both the servers. mod_rewrite was enabled and everything was fine from server side. Can someone help me what can be the issue
Not exactly an answer but too large for a comment:
switch (ENVIRONMENT) {
case 'development':
error_reporting(~E_DEPRECATED);
ini_set('display_errors', 1);
break;
case 'testing':
case 'production':
error_reporting(~E_DEPRECATED);
ini_set('display_errors', 1);
break;
default:
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'The application environment is not set correctly.';
exit(1); // EXIT_ERROR
}
Change production to have the same error_reporting as development so you will get the errors instead of seeing a generic 500 page.
I don't believe you .htaccess file is at fault here as you wouuld get a 400 rather than a 500 (internal server error).
you can try this:
upload htaccess file in root
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options -Indexes
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

Force HTTPS and remove index.php on CodeIgniter

So I'm using this .htaccess script on my VPS but it doesn't work on the point where it should remove the index.php from the url.
<IfModule mod_rewrite.c>
RewriteEngine On
#Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.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>
Options -Indexes
As I said everything is fine with the redirect but the when I want to open domain.com/projects it's not found error but if I add domain.com/index.php/projects everything is fine...
In application/config/config.php change:
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
Check your VHost file, make sure it looks like
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs\http"
ServerName localhost
</VirtualHost>
and not like
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\http"
ServerName localhost
</VirtualHost>

Codeigniter htaccess index.php site down

Codeigniter htaccess started problem suddenly even when no changes were made to any files. I can access
www.mysite.com/index.php/controller/method
but when I access
www.mysite.com/controller/method
it gives a general 404, not a codeigniter 404. Any help is appreciated. The site is down.
Here is my present 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
#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|images|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>
In this case i'm 100% sure your mod_rewrite is not working properly.Also make sure your .htacess file is in your root directory. A have this one working properly on my server may be this will help you :-
# rewrite rules
RewriteEngine On
# ditch index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

htaccess and mod_rewrite codeigniter

I am using codeigniter and below is my htaccess file. However, i want a single directory to be accessable outside of the codeigniter app via my domain.com/directory. the other directory is a forum not related to codeigniter. how would i set up a rule in htaccess? i dont have access to http.conf
<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>
This should already work. RewriteCond %{REQUEST_FILENAME} !-d tells mod_rewrite to ignore actual directories, and RewriteCond %{REQUEST_FILENAME} !-f tells it to ignore actual files.
I use this to exclude any folder from being parsed to codeigniter framework as a controller.
So www.domain.com/images/ would run as normal folder, etc. There you can put your individual directives of htaccess. Best of luck!
RewriteCond $1 !^(folders_to_exclude_from_CI|images|css|assets|resources|robots\.txt)

How can I remove index.php using Codeigniter on XAMPP?

I can't hide Codeigniter index.php on XAMPP 1.7.3
URL:
http://localhost/Servidor/agentesRainbow/index.php/agentes/tony
tony is an argument
My actual .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Servidor/agentesRainbow/
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /Servidor/agentesRainbow/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|css|public|)
RewriteRule ^(.*)$ /Servidor/agentesRainbow/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 /application/errors/404.php
</IfModule>
My routes.php:
$route['agentes/(:any)'] = "agentes/index/$1";
$route['default_controller'] = "agentes";
$route['scaffolding_trigger'] = "";
My config.php:
$config['base_url'] = "http://localhost/Servidor/agentesRainbow/";
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
On httpd.conf:
LoadModule rewrite_module modules/mod_rewrite.so
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory /Servidor/agentesRainbow/>
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
Add this line to the REQUEST_FILENAME conditions:
RewriteRule ^(.*)$ /Servidor/agentesRainbow/index.php/$1 [L]
Here is the updated .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Servidor/agentesRainbow/
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /Servidor/agentesRainbow/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 ^(.*)$ /Servidor/agentesRainbow/index.php/$1 [L]
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|css|public)
RewriteRule ^(.*)$ /Servidor/agentesRainbow/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 /application/errors/404.php
</IfModule>
Hope it solves your problem!
I think the bar at the end of the rewrite condition is causing a problem. At least it broke the rewriting for me.
RewriteCond $1 !^(index\.php|images|css|public|)
Try removing the bar.
RewriteCond $1 !^(index\.php|images|css|public)
base_url should be just "http://localhost";
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|other|directories|you|want|accessible|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Resources