Remove index.php from url in codeigniter-3 in ubantu14.04 - php

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

Related

Remove index.php when access using ip address

I uploaded codeigniter project on server.Removing index.php from URL is not working. I access it using IP address. like http://ip address/
Below is my htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
/etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
I tried all possible solutions found on google. but not working for me.
Please follow some step:
goto application/config/config.php :
replace $config['index_page'] = 'index.php'; to $config['index_page'] = '';
and
$config['uri_protocol'] = 'REQUEST_URI'; to $config['uri_protocol'] = 'AUTO';
enable rewrite mode by
sudo a2enmod rewrite
then
service apache2 restart
if you'd like, you can use the following .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
in httpd.conf, edit or delete "index.php":
<IfModule dir_module>
DirectoryIndex index.php
</IfModule
Then in htaccess, add this:
Options -Indexes
Add below code in .htaccess. Hope this work.
Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
Set your .htaccess as below
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Then open /etc/httpd/conf/http.conf file and find <Directory "/var/www/html"> with in this find and set AllowOverride None to AllowOverride All.

How to remove index.php from URL in CodeIgniter using .htaccess

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"

htaccess RewriteRule doesn't work properly

I have this code in my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?link=$1 [L]
</IfModule>
And I am getting 404 although I can acces it with non-pretty url like this index.php?link=somepage
My full url is http://www.website.com/subfolder/index.php?link=somepage
I have Apache 2.4.18 on Ubuntu 16 and mod_rewrite module is loaded.
Update
Also when I try with this:
RewriteRule ^ index.php [L]
Then I can access it with http://www.website.com/subfolder/?link=somepage
So this way it works when just removing index.php
Is it possible that some additional configuration has to be set on server?
This was a server issue including mime types and multiviews.
It's not really issue for stackoverflow but if someone runs into same problems here are sources that solved this problem:
http://www.bennadel.com/blog/2218-negotiation-discovered-file-s-matching-request-none-could-be-negotiated.htm - remove MultiViews from Virtual Host configuration
https://serverfault.com/questions/372733/apache-file-negotiation-failed - add missing mime types
Try :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/index.php?link=$1 [L]
Try with this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./index.php?link=$1
First of all you should check your apache config
sudo vi /etc/apache2/apache2.conf
Search for
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Change AllowOverride None to AllowOverride All
enable htaccess module by running cmd
sudo a2enmod rewrite
then restart your server
sudo service apache2 restart
and use this .htaccess file in your project folder
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
Hope it works for u .. :)

Htaccess for multiple website codeigniter

i have a website with subdomain.
I trying to searching i google but still not worked with my projects.
my structure folder is :
-public_html
--subdomain_folder (this is codeigniter)
---htaccess_for_subdomain
--domain_folder (this is my own projects website)
---htaccess_for_domain
--htaccess_for_root
below is my htaccess code :
htaccess_for_root (public_html)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.go.id$
RewriteRule ^(.*)/^(.*)/files/source/(.*)\.(gif|jpg|png|jpeg|css|js|swf|JPG)$ files/source/$2.$3 [QSA]
RewriteCond %{REQUEST_URI} !^/domain_folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domain_folder/$1
# Change yourdomain.com to be your primary domain again.
# Change 'subfolder' to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?domain.go.id$
RewriteRule ^(/)?$ domain_folder/index.php [L]
****this is my htaccess_for_domain****
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/files/source/(.*)\.(gif|jpg|png|jpeg|css|js|swf|JPG)$ files/source/$2.$3 [QSA]
RewriteBase /web/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /domain_folder/index.php [L]
This is htaccess_for_subdomain
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index.php/(.*)$ /$1 [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
When i access my subdomain (www.sub.domain.go.id) it always not redirecting properly.
and what i want is, when i access www.domain.go.id it will redirect to domain_folder and when i access www.sub.domain.go.id, it will redirect to subdomain_folder
Thanks
I think the best solution for you is to use virtual hosts and set the documentRoot for each domain/subdomain to point to its specific folder.
Eg. (apache - I suppose you use apache as a web server)
<VirtualHost *:80>
ServerAdmin administrator#localhost
ServerName www.sub.domain.go.id
DocumentRoot /path/to/your/project/public_html/subdomain_folder
<Directory /path/to/your/project/public_html/subdomain_folder/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.sub
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
</Directory>
</VirtualHost>
Do the same thing for your domain to point to the domain_folder.
You can find more details about virtual host for apache in this link
https://httpd.apache.org/docs/2.4/vhosts/

Installing codeigniter on subdomain but it is giving 500 internal server error

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!

Categories