I am facing problem while removing index.php from url in Codeigniter 3 using Wamp Server. I was changes in file config.php (project_folder/application/config/config.php)
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = "REQUEST_URI";
and create .htaccess file same level of application folder with code written
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|opensearch\.xml|favicon\.ico|assets|forums)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
and rewrite_module is on and my virtual host code is
<VirtualHost *:80>
DocumentRoot "D:/work/project_Name/"
ServerName abc.local
<Directory "D:/work/project_Name/">
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
using these changes and code my project not run without index.php and error throw
abc.local/controllername
Not found
The requested URL /controllername/ was not found on this server.
Thanks!
Try this code on .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
And on config.php page set $config['base_url'] ="http://localhost/project/" and $config['index_page'] = ''; and $config['uri_protocol'] = 'AUTO';
Try these:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /folder_name_of_project/
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
RewriteCond $1 !^(index\.php|images|stylesheets|javascript)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Related
I know this question is asked many times before and I've gone through most of them already but couldn't find a solution. I've tried most of the answers given here, here and in CodeIgniter official documentation. And restarted apache each time. It didn't work for me. mod_rewrite is already enabled in my apache server.
Weird thing is, I've a working example for WAMP (in my laptop):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /project/index.php
</IfModule>
It works perfectly in WAMP, but it doesn't work in LAMP. Any kind of help is appreciated.
Please use below code:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I have used this and it is working.
Try Below code in your .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ROOT DIRECTORY NAME/
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<Directory "/path/to/document/root/">
AllowOverride All
Allow from All
</Directory>
Just like this......
.htaccess inyour root directory with following code..
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Set configuration in application/config.php as follows..
$config['base_url'] = 'http://domain_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
I made it working with the help of following .htaccess code:
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
And I updated <Directory /var/www/> section of /etc/apache2/apache2.conf file with:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
It solved all problems and now it works fine.
here it is my approach:
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
And also in config.php replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
and also in the same file replace
$config['uri_protocol'] ="AUTO"
by
$config['uri_protocol'] = "REQUEST_URI"
I have Ubantu 14.04 machine also I checked Link
My phpinfo() says rewrite_module is Enable also I have done changes into config.php
$config['index_page'] = '';
and below is my .htaccess file on root
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Try this one
Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
# Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
I got solution just added
<Directory /var/www/html >
Order allow,deny
AllowOverride All
Allow from all
Require all granted
</Directory>
into file /etc/apache2/sites-available/000-default.conf and it's working fine
I have installed the codeigniter on subdomain like http://abc.domain.com.
I have modified my htaccess file but it is giving 500 internal error. Please
tell me required changes to be done in htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /abc
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Change the RewriteBase to / only and add base_url to your config file like,
# in htaccess change the RewriteBase
RewriteBase /
in application/config/config.php
$config['base_url'] = 'http://abc.domain.com/';
Also make sure that your htaccess file should be in your abc folder, not on the root www
Firstly I hope you have configured your virtual host properly.
For example:
<VirtualHost *:80>
ServerName abc.domain.com
DocumentRoot /var/www/html/abc/or/whatever/
</VirtualHost>
And your Directory directive
<Directory /var/www/html/abc/or/whatever/>
AllowOverride all
</Directory>
Then place this in the /var/www/html/abc/or/whatever/.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index.php|images|captcha|css|js|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
This should work in most cases. And don't forget to restart apache!
I have big problem trying to remove index.php from url's
i have searched lots if forums (this also), but no help for my situation.
so i have config.php file
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
my .htaccess file in public_html folder near index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /public_html/
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>
and in WAMP apache (ver.: 2.4.9) i have rewrite_module ON (and it's working)
and my httpd.conf AllowOverride set to All
so when i am going to mydomain.com/controller/action - I get 404
but when i go to mydomain.com/index.php/controller/action - everything is OK..
i have tried lots of .htaccess examples... and so on.. nothing helps..
Use this htacess and then go to config.php and remove index.php
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Hi all im trying to hide the index.php from the url, well something like that:
i want : mydomain.com/index.php/mycontroler
to be like : mydomain.com/mycontroler
here is my .htaccess
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
And here is my conf.php
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
the problem is that it was working good in the local but not in the server
here is the disposition of my files
- bin
- etc
- mail
- public_ftp
- public_html
-- application
-- assets
-- system
-- .htaccess
-- index.php
Help guys
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
$config['index_page'] = '';
htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
if still getting troubles try changing :
$config['uri_protocol'] = 'REQUEST_URI';
to
$config['uri_protocol'] = 'AUTO';
or somenthing different more (in the config.php you'll find all the options available to try for the uri_protocol param)
Here is .htaccess stuff,
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
RewriteEngine on
# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
#RewriteBase /
# Restrict your site to only one domain
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
#prevent access to htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
#disable directory browsing
Options All -Indexes
IndexIgnore *
And in config.php
Set base URL like 'http://www.example.com/'
Set $config[‘index_page’] to an empty
string Set $config['uri_protocol'] = 'REQUEST_URI'
all my .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|static)
RewriteRule ^(.*)$ /index.php/$1 [L]
and you should make sure that property AllowOverride is set correct, eg:AllowOverride ALL in your httpd.conf Directory segment
Make the below changes in the root .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
It worked for me.