I am newbie in Codeigniter and trying to configure Codeigniter.
But i am unable to remove the index.php from url..
I changed the .htaccess file by following data which was given in userguide..
.htacess file contains
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and also changed the config file
$config['index_page'] = '';
when i try to use the following url it results
The requested URL /codeigniter/pages/view was not found on this server.
http://localhost/codeigniter/pages/view
But i try with index.php in url..The page shown normally..
http://localhost/codeigniter/index.php/pages/view
Is that .htaccess problem or i have to change some other files..?
How to get rid of this problem?
Any Suggestions, acceptable.
Update
I am using ubuntu 3.10
I used the following command to enable module rewrite
sudo a2enmod rewrite
The result as follows
Module rewrite already enabled
I changed the permissions in
/etc/apache2/sites-enabled/000-default
As
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
After changing this file also no luck..
Finally i found the answer to my question.As the below .htaccess solved my problem..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.+)$ index.php?/$1 [L,QSA]
</IfModule>
Thanks to all..
in your httpd.conf (on windows)
uncomment below line
LoadModule rewrite_module modules/mod_rewrite.so
in ubuntu
enable mod_rewrite using sudo a2enmod rewrite
Restart apache after making changes
Make this changes
In config.php
$config['index_page'] = '';
IN root .htaccess file
DirectoryIndex index.php
RewriteEngine On
RewriteCond $1 !^(index\.php|themes|utils|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L]
Nobody mentioned change the setting. In your httpd config file find and change it like this
<Directory "/var/www/html"> # your DocumentRoot setting
Options FollowSymLinks
AllowOverride All # default is None
Order allow,deny
Allow from all
</Directory>
Related
I'm not sure what the problem is I followed the steps to remove index.php
Added to .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Selected Custom Structure
http://11.33.55.77/%pagename%/
Any page I visit is a 404 for example
http://url.com/faq = 404
The requested URL /faq was not found on this server.
Make sure the permalink of the faq page is actually /faq, if that's set up properly make sure mod_rewrite is enabled in your apache
Make sure mod_rewrite is enabled. sudo a2enmod rewrite.
This did not work for me
instead go to apache2/sites-available/default-000.conf
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
copy and paste the following configuration
I created web app with Laravel, which I tested on laravel server ( php artisan serve ) and now I want to put it on LAMP so I can test it further, but something is wrong.
When I visit localhost/public/ I get my home page but when I click on any link inside my app I get Not found error. On the other side, when I manually input localhost/public/index.php/someURL then I get the linked page.
Can someone tell me how to fix this?
This is my .htaccess file inside public directory:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<IfModule mod_deflate.c>
<FilesMatch "\.(html|php|txt|xml|js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
This is the content of apache2 conf file ( /etc/apache2/sites-available/000-default.conf ) :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
<Directory "/var/www/html">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And I enabled mod_rewrite with this command: sudo a2enmod rewrite
I'm using Ubuntu 14.04.
UPDATE:
App is placed inside /var/www/html/
Go to /etc/apache2/apache2.conf file and make sure it looks like this:
<Directory /var/www/html>
Options Indexes FollowSymLinks
Allowoverride All
Require All Granted
</Directory>
You can locate it right after
<Directory /usr/share>
....
</Directory>
Perform mod_rewrite and restart apache and it should work!
This is how I fixed it. I created another .htaccess file and placed it in root directory /www/html/:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Information taken from here: http://driesvints.com/blog/laravel-4-on-a-shared-host
Im using laravel 4.
I have a view nest.blade.php and the corresponding controller NestController.php:
Controller content:
class NestController extends BaseController {
public function showView()
{
return View::make('nest');
}
}
Route:
Route::get('/nest', 'NestController#showView');
When I go to url/nest it doesnt work.
When I go to url/index.php/nest it does work.
Obviously I just want it to be /nest without the index.php.
How can i resolve this?
My htaccess:
IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Pretty URLs
The framework ships with a public/.htaccess file that is used to allow
URLs without index.php. If you use Apache to serve your Laravel
application, be sure to enable the mod_rewrite module.
If the .htaccess file that ships with Laravel does not work with your
Apache installation, try this one:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
For more related help, check this answer.
I enabled the mod_rewrite module in the Apache HTTP server, restarted Apache service and tested again and it WORKED!!!
Below is the code i used to enable mode_rewrite;
1) Un-Hash this line in Apache/conf/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
2) Create a new configuration for "sample-project" without modifying the default configuration in the httpd.conf file
Directory "C:/Apache24/htdocs/sample-project">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Directory>
Be Alert! If it is not working even after enabling rewrite module. You need to change the line "AllowOverride None" to "AllowOverride All" in httpd.conf.
As #The Alpha alerted, Laravel don't need to be configured for this purpose.
When you change the line AllowOverride None to AllowOverride All in httpd.conf be sure that you do it inside <directory ...> that contains valid path.
Example
<Directory "/var/www/html"> #check path
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
For some reasons the answers above are not working for me, so here is the only one that worked for me.
I am using ubuntu 18.04 amd64 as my development server environment.
So I modified apache.conf file located at/etc/apache2
From:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted
To:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted
And Also From:
<Directory /usr/share> AllowOverride None Require all granted
To
<Directory /usr/share> AllowOverride All Require all granted
After that, you need to restart apache using sudo service apapche2 restart command in the terminal
Now I can access the page without using index.php in the URL
Credit goes to: joshymatheww # Laracasts servers discussion channel on
Aug 5, 2017
Login to the terminal
sudo nano /etc/apache2/apache2.conf
After line
<Directory /var/www/>
.
.
.
</Directory>
and paste below code
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
Now Ctrl+O and then Ctrl+M and then Ctrl+x
Now restart apache server
sudo service apache2 restart
First of All you need to set AllowOverride All in /etc/apache2/apache2.conf. Find the following block:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
DirectoryIndex index.php
Require all granted
</Directory>
then you need to modify /etc/apache2/mods-available/dir.conf and move index.php first :
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
AND DO NOT FORGET: Run a2enmode
sudo a2enmod rewrite
and then
sudo service apache2 restart
This way you apply it for all your laravel projects (inside /var/www/ folder).
set this in your .htaccess
DirectoryIndex index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
Try the following .htaccess. I never had any trouble with that on a server or localhost environment.
DirectoryIndex index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>
I have researched on all the question on stackoverflow to remove index.php from codeigniter but still i am unable to do it. Only landing page opens but rest of the pages are blank.
I m using own ubuntu linux server.
My rewrite module is also on. I tried $config['uri_protocol'] with all possible values. AUTO, PATH_INFO, QUERY_STRING, ORIG_PATH_INFO.
My htaccess code is here
RewriteEngine on
AddType text/x-component .htc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
vhost file is here
DocumentRoot /home/black-sheep/black-sheep.org
<Directory />
Options FollowSymLinks
AllowOverride FileInfo
</Directory>
<Directory /home/black-sheep/black-sheep.org/>
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
My website url is
http://black-sheep.org/
This is the path when i echo __FILE__ on index.php
/home/black-sheep/black-sheep.org/index.php
Its amazing that wordpress site on same server without index.php is running good with following htaccess.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I tried with this htaccess also but it doesn't work for me.
Please suggest me the solution.
Thanks in advance
I have same problem. And I fix it.
You must add .htaccess file in root directory of your site
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
And main you must change site conf in /etc/apache2/apache2.conf. Search Directory /var/www/
Change AllowOverride None -> AllowOverride All
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
How to remove index.php in localhost(Ubantu) using codeigniter
sudo nano /etc/apache2/apache2.conf
write this code below.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
within codeigniter framework config/config.php
In application/config/config.php change:
$config['index_page'] = 'index.php';
to:
$config['index_page'] = '';
$config['base_url'] = 'http://localhost/code_test';
make .htaccess file main folder directory
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
Try this solution.
Paste this below code into .htaccess file and move it to you codeigniter folder
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
I was facing the same problem but able to correct it. I am giving you the full instruction. follow step by step..
First check whether mod_rewrite is on or not from Terminal by typing the below command :
sudo a2enmod rewrite
Then open file apache2.conf which is located in the below mentioned directory
/etc/apache2/apache2.conf
Find <Directory /var/www/> in the file and change AllowOverride None to AllowOverride All
If it is not allowing you to save the file, that means the directory don't have the required permission. so please give that by running the below command.
sudo chmod -R 777 /etc/apache2/ and then save the file.
Now write your .htaccess file and save the file by placing the below codes.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
Then restart your apache service once by the below command
sudo service apache2 restart
Hopefully, then it will work...
I know it is the most repetitive question of CI.
I am using Kubuntu and have made following changes
$config['base_url']='http://localhost/cii/';
$config['index_page'] = '';
$config['uri_protocol']= 'REQUEST_URI';
I've kept my .htaccess file where index.php is kept (in the root folder) but am getting following error:
The requested URL /cii/welcome/second was not found on this server.(404 error)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Possibly the problem is due to the AllowOverride None of document root path in apache sites-available configuration file. You need to modify the line containing AllowOverride None to read AllowOverride All in the file (/etc/apache2/sites-available/default) to make .htaccess files work as expected. Do restart apache once after made the changes.
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Enabling use of Apache htaccess files.
I would guess that the error is because your CI is located at the subfolder /cii but the rewrite rules point to the root folder.
Try adding RewriteBase /cii/ inside the first block.