codeigniter removing index.php (possible problem with host) - mod-rewrite

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.

Related

CodeIgniter routes not taking effect

I just copied a codeigniter project from one folder to another in my XAMPP htdocs. These two projects contain exactly the same code, they're just in different directories.
In the copied project, the default_controller works fine but none of my routes work.
my routes:
$route['default_controller'] = 'home';
$route['404_override'] = '';
$route['dashboard'] = 'dashboard';
The index file is located at localhost/project/www
If I go to localhost/project/www/dashboard, I get a 404.
But if I do this:
$route['404_override'] = 'dashboard';
Then the dashboard controller loads correctly when I go to localhost/project/www/dashboard (or any other path, which would give a 404, of course)
The problem is not in the .htaccess file, since it's just generic:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Like I said, the code has just been copied from one directory to another. Any ideas as to what is preventing my routes from working properly? Have I missed something?
EDIT
After setting the 404_override and removing it again, the routes magically worked again. Everything is fine.
If anyone could shed a light on why this has happened, that might help the next guy who gets in this situation. But for me, the problem is resolved.
OK, the problem was that I had used uppercase for the name of the copied project, but was trying to access it with lowercase on a system that discerns between these two.
So, stupid
i think problem is you were using doing like this
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
instead you try it
RewriteEngine On
RewriteBase /www/
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

How to remove index.php in Wamp?

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.

codeIgniter Index.php Removal from URL

I know this question has been asked one thousand time. But I have problem applying it to my project however.
What I do: I have copied the following code (suggested by CI Docs) in .htaccess file in my application folder:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
PROBLEM: it does not work and it throws 404 or Internal Error. I also have tries creating new .htaccess file in my root folder, or copying the above code in system folder's .ht . none of them works. 404 or internal error are inervitable
paste the following code in your htaccess file inthe root folder
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
and the in the config.php file change the line with
$config['index_page'] = '';
please let me know if you face any problem.
Try this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
and in config.php
$config['index_page'] = '';
Thanks everybody. it is done. The problem was that I had not activated the APACHE rewire_module
Sorry if I wasted your time.
thanks

Codeigniter Index file issue

I have already worked in the CI. But this time when i remove the index file. I am getting 404 error. But i did everything correctly. Here is the settings i have done.
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/javascripts|files\/stylesheets|files\/swf|files\/upload)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /qrout/index.php/$1 [L]
Config File
$config['base_url'] = 'http://webscarlets.in/projects/';
$config['index_page'] = '';
I hope above settings are all correct. And i have tried added this 'qrout' folder in the base url still it's not working
Here is the website link
http://webscarlets.in/projects/qrout/welcome
Kindly guide me to solve this issue.
Thanks to all.
Try to use this condition .....ITs working for me
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
It looks like your rewrite condition is targeting js files and things like that. Those files don't need the index.php in their path. Only your Codeigniter files will.
I'd rework that conditional statement.

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

Resources