How to remove index.php in Wamp? - codeigniter

I 've been using CodeIgniter in XAMPP.
There was no problem to redirect to a function URL (e.g., function1):
http://localhost/function1
When I changed to WAMP, I got a problem. I could not redirect to function1. However, function1 is still accessed at:
http://localhost/index.php/function1
How to configure WAMP and CodeIgniter to remove index.php?
In order that I could run function1 as I run using XAMPP.
Thank you.

Please try the following:
1) Create .htaccess file in parallel to application folder and just copy paste the following code:
RewriteEngine On
RewriteBase /CodeIgniter/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
2) Change $config['index_page'] to blank in config.php in application folder as below:
$config['index_page'] = '';
3) Enable "rewrite_module" of apache. Click on WAMP symbol -> Apache -> Apache modules -> rewrite_module
Now you can access your site without index.php in url.

Create an .htaccess file if you didn't already have one and add this code in it:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Make sure you place this in the same directory as your index.php.

Only three steps are require to remove index.php from url in Codeigniter in WAMP environment.
1) Create .htacess file in parallel to application holder and just copy past the following code:
RewriteEngine On
RewriteBase /CodeIgniter/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
2) Change $config['index_page'] to blank in config.php in application folder as below:
$config['index_page'] = '';
3) Enable “rewrite_module” of apache.
Restart your apache and its done.
Details : http://sforsuresh.in/removing-index-php-from-url-of-codeigniter-in-wamp/

The mod_rewrite rule suggested in CodeIgniter's official documentation at http://ellislab.com/codeigniter/user-guide/general/urls.html which is
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
worked perfectly for me on WAMP
This would also work:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
In these two variations, the only difference is the condition. Basically, what matters is the rewrite rule. Condition can depend on your requirement.
Both of these were not working for me earlier on WAMP. However, the problem was in Apache settings. rewrite_module was not enabled. So, do check that is enabled. You can check if it is enabled by using phpinfo() and check the Loaded modules list.
If you it is not enabled, you can enable it using the WAMPserver manager (accessing it from task bar) Go to Apache>Apache Modules and check 'rewrite_module'
OR
Open httpd.conf and check if LoadModule rewrite_module modules/mod_rewrite.so is uncommented.
You will have to restart WAMPserver to activate the changes.

Related

In codeigniter redirecting is not working without index.php?

I am new to codeigniter while redirecting a page index.php is not loading by default,So i have tried the below code in htaccess file. I have installed php 5.3.10, apache server and postgres database. so if any new configuration have to be done apart from changing .htaccess and httpd.conf then please let me know. I have seen previous questions asked on the same issue and i referred everything from those questions but still I am not able to solve this. please let me know what extra things to be done.
.htaccess file
<IfModule mod_rewrite.c> RewriteEngine On #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|public|images|robots\.txt|css) RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^/(index\.php|assets/|humans\.txt) RewriteRule ^(.*)$ index.php/$1 [L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
httpd.conf file
ServerName localhost
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
Following things you should do for avoiding index.php in url
Always make sure you have .htaccess file. which you have already.
Include contents in .htaccess which #charlie has suggested above.
Edit httpd.conf file using nano command and include main thing keep allowoveride All
First disable rewrite mode and enable it again then restart apache2 server using following commands.
sudo a2dismod rewrite //which disables the rewrite mode
sudo a2enmod rewrite //which enables the rewrite mode
sudo service apache2 restart //which restarts your apache
Thats all you need to do. All the best.
Paste this in your .htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Codeigniter URL not working without index.php

I've just set up a new webiste http://www.reviewongadgets.com
But there is a problem with URL rendering
When I put an URL as below it's not working and gives page not found error
http://www.reviewongadgets.com/latest-mobile
But it works with
http://www.reviewongadgets.com/index.php/latest-mobile
I don't want to show index.php in my URL, it should be http://www.reviewongadgets.com/latest-mobile
, can you please suggest me what should I do ?
This is my .htaccess file contents:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Config file contents:
$config['base_url'] = "http://www.reviewongadgets.com";
$config['index_page'] = "";
Same type configuration working for my another website
Changed my .htaccess content to
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
The most common solution to this problem is usually the missing question mark ? after index.php in .htaccess, so
RewriteRule ^(.*)$ index.php/$1 [L]
should be
RewriteRule ^(.*)$ index.php?/$1 [L]
E.G. on my Windows XAMPP, I do not need the "?", but in a Linux hosting environment it is usually required.
i aggree with Vlakarados, but i will share my .htaccess setting
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
its work perfectly.
i hope that's work to for your CI website
You might not have rewrite_module module loaded.
Try running below command.
sudo a2enmod rewrite

mod_rewrite for codeIgniter

Has anybody in the history of the internet and web development, been able to get rid of the "index.php" with mod_rewrite in codeIgniter.
I've been trying for several days now and nothing seems to work.
I'm using this one (in .htaccess file):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
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>
Not sure where I got it but it works for my codeigniter install, local and live. Don't forget to set $config['index_page'] = ''; in your config file.
For mod_rewrite use the following in your .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
If your codeigniter instance is running in a subdirectory then use the rewrite base command before the RewriteRule
RewriteBase /subdirectory/
Then set
$config['index_page'] = '';
In the config file.
You might have your .htaccess file in the wrong place. CodeIgniter has a default .htaccess placed in the applications folder, which I mistakenly took for the one I should edit.
You actually need to create a new .htaccess under the root folder. So not code_igniter/applications/.htacces...but code_igniter/.htaccess
Hope this helps.
Yes, I configured it under Linux using the instructions from here. However, I configured it via httpd.conf instead of using .htaccess.
I have used the settings provided above and they always worked - unless I did not have mod_rewrite enabled.
If you are having issues check to ensure you have mod_rewrite enabled. If you do not it will not matter what you put into .htacess or your Apache config

CodeIgniter - removing index.php

Im having some trouble removing the index.php thing on my CI install, the current .htaccess im using is as follows:
<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>
ErrorDocument 404 /index.php
</IfModule>
My CI install is back from the public_html directory and i have changed the config to
$config['index_page'] = "";
So my CI looks like the following
/core-1.7.3
/public_html/index.php
When i type the url i get the 404, but when i put index.php in front of it, it works fine :S
Im confused
Hi
I ve installed that 1.7.3 and this .htaccess worked with this URL-
/CodeIgniter_1.7.3/public_html/welcome
.htaccess->
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Work through Avisek Chakraborty's comment and make sure you've done them all, but
it sounds to me like you don't have mod_rewrite installed correctly.
Make sure it is by using the following test:
http://www.wallpaperama.com/forums/how-to-test-check-if-mod-rewrite-is-enabled-t40.html
It is written for windows but you should get the idea.
If it doesn't work then install mod_rewrite and try again.
Also try to change this:
$config['uri_protocol'] = “REQUEST_URI”
You need the FollowSymLinks directive for .htaccess rewrites ...
Options Indexes FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
The Options directive is in The Apache Docs

codeigniter removing index.php (possible problem with host)

Hi everyone I'm having some problems when removing index.php in CodeIgniter.
I created my application locally and it works fine but when I uploaded it, removing index.php doesn't seem to work.
I have a feeling this could have something to do with my host, it's not the best and I've had problems before. It's hosted on Fatcow.
So..
all my CodeIgniter files are located in a sub-dirctory called outfitr. e.g
<root>/outfitr/
I have my .htaccess file located in this folder with the following taken from the CI wiki:
EDITED
RewriteEngine On
RewriteBase /outfitr/
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]
changes fo my config.php look like the following. I have enabled query strings as I need them for a section of my application.
$config['base_url'] = "<host>.com/outfitr/";
$config['index_page'] = "";
...
$config['uri_protocol'] = "PATH_INFO";
$config['enable_query_strings'] = TRUE;
Any help would be great. As I said I think it might have something to do with the host Fatcow.
I have tested mod_rewrite, following the steps on the following page and it seems to be enabled.
http://www.wallpaperama.com/forums/how-to-test-check-if-mod-rewrite-is-enabled-t40.html
ok so after some trial and error I finally got it working. I setup my .htaccess file as follows. Note the '?' in RewriteRule.
RewriteEngine On
RewriteBase /outfitr/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
Then in config.php I set
$config['uri_protocol'] = 'REQUEST_URI';
Think this is down to the way some hosts setup their mod_rewrite module. Dreamhost and hostgator have the same problem.
http://codeigniter.com/wiki/mod_rewrite/
If your installation is not in the server root you will need to amend the RewriteBase line from “RewriteBase /” to “RewriteBase /folder/”
The current .htaccess you have is re-routing all requests to /index.php, which as you said yourself is not there. You want them to route to /outfitr/index.php.
You can do this by changing the RewriteBase /outfitr/
If not, please give more detail.

Resources