I am running Apache 2.2.22 on Ubuntu 12.04.3 (Oracle VM on Windows 8.1).
Using the PHP phpinfo() function I see mod_rewrite in the apache2handler section under Loaded Modules, so mod_rewrite is enabled.
I made the following changes to my CI config file (application/config/config.php),
$config['index_page'] = 'index.php'; to: $config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; to: $config['uri_protocol'] = 'PATH_INFO';
I have tried numerous versions this(.htaccess file located in the root directory of CI ):
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
but have yet to get it to work.
What else am I missing here?
This worked!
RewriteEngine On
RewriteBase /testsite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Working on the assumption that your folder structure is something like... /var/www/html/testsite and your url is localhost/testsite, then the above rewrite rule will be looking for index.php in /var/www/html and not /var/www/html/testsite.
( /var/www/html will be the default document root. )
So in your equivalent folder of /var/www/html/testsite you can try using the following in your .htaccess file located in /var/www/html/testsite/. so you'd have /var/www/html/testsite/.htaccess with the code...
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
All I have done is removed the leading / in the rewrite rule in the last line so it's not heading back to the default document root.
Related
My site http://www.bishal.prtia.com/prT_base/ throw an 404 error while loading in the server.
It works perfectly in the localhost. I tried changing everything that mentioned in this forum like changing .htaccess to web.config and changing base url routing config etc but it still throws an error.
Check the following things once again:
Make sure your base_url is proper as per your website address, not localhost
Check routes.php file for default controller and make sure it is correct.
Make sure .htaccess looks like
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|js|css|upload|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
Then check following thigs:
Config.php
$config['base_url'] = 'http://www.bishal.prtia.com/prT_base/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Routes.php
$route['default_controller'] = 'your controller name (like welcome)';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Make sure php file name of controller start with capital letter like Welcome and also inside that file as well when inherit from CI_Controller
Function inside Welcome.php:
public function index()
{
$this->load->view('your view file');
}
Thanks
You need to do few steps.
Update base_url in config.php
Update RewriteBase in .htaccess
Set Permissions
if still not workable, add error_reporting(E_ALL) in index.php and see what it says
I also faced this error. I changed my .htaccess file [WORKED FOR ME] :-
.htaccess for Live Server :-
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
.htaccess for Localhost :-
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1
http://localhost/codeigniter/index.php/user/main_page
how can you remove index.php from this url ?
Try this file. I use it in my projects
https://github.com/eborio/curso-de-codeigniter/tree/master/02-primeros-pasos
The answer is in the post that this question is ducplicated of.
This is the answer
Sean Vieira's answer:
If you are using Apache place a .htaccess file in your root web
directory containing the following:
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Another good version is located here:
http://snipplr.com/view/5966/codeigniter-htaccess/
Try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Replace:
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
if it still not work try to replace:
$config['uri_protocol'] = "AUTO"
//replace with the below code
$config['uri_protocol'] = "REQUEST_URI"
for more details: http://w3code.in/2015/09/how-to-remove-index-php-file-from-codeigniter-url/ check this
My directory structure is /var/www/CI/ with all the folders viz., application, system under the folder CI. Have created a .htaccess file under CI.
Following is the code in .htacess.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Still localhost/CI/blog gives 404 error. Can anyone guide as to where this rule is wrong?
Please try the following
At first, make sure you set the config file like the following..
$config['index_page'] = '';
Also make sure that mod_rewrite is enabled in the httpd.conf file and after that, overwrite your .htaccess file which is located your project root folder not in the application folder with the following code..
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
Make sure in your application/config/config.php file this is set as follows:
$config['index_page'] = '';
Also do this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^CI/(index\.php|public|images|robots\.txt|css)
RewriteRule ^CI/(.*)$ CI/index.php/$1 [L]
</IfModule>
Typically you don't put CI in its own directory and put application and system in the root folder.
Check your Apache configuration so that it is allowing an override.
If the AllowOverride is set to None, the rewrite won't work for you.
Adding the following to your httpd.conf (NOT your .htaccess) should fix your problem
<Directory "/">
AllowOverride All
</Directory>
Let me know if it's still not working.
This works. Although, please make sure your mod_rewrite is enabled,
Find the httpd.conf file under the C:\wamp\bin\apache\apache2.4.9\conf folder inside the Apache’s installation folder.
Find the following line #LoadModule rewrite_module modules/mod_rewrite.so in the httpd.conf file.You can do this easily by searching the keyword “mod_rewrite”.
Remove the # at the starting of the line, # represents that line is commented.
Then restart the apache server.
You can see now mod_rewrite in the Loaded Module section while doing phpinfo().
Use the following steps,
1. Create .htaccess file in the document root [myroot_folder/.htaccess].
2. open the config file in application/config/config.php and do the following
$config['index_page'] = '';
remove index.php from your base url
if it is $config['base_url']= 'http://localhost/myroot_folder/index.php';
change it to $config['base_url']= 'http://localhost/myroot_folder/';
Now open the .htaccess file and add the following code block
DirectoryIndex index.php
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]
1) Make .htaccess file and put this code.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
2) Change:
$config['index_page'] = '';
remove index.php present in config.php file
3) Rewrite on from your server
If you have not worked all but that you did so, try this:
Change AllowOverride None to AllowOverride All in the virtual host file in /etc/apache2/sites-available/default
Details here
This ones a new on me. I'm transferring a site I made in codeigniter to a godaddy shared hosting server. I can get to the home page with:
http://www.example.com
But when I try to go to the other pages like:
http://www.example.com/about-us/
It throws me this error message:
Not Found
The requested URL /example/index.php/about-us/ was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
If I use:
http://www.example.com/index.php/about-us/
The page appears as clear as day.
I have looked up CI workaround , but my site is more of static pages then dynamic pages.
Overall, my question is, what am I doing wrong and does this have anything to do with having a godaddy shared hosting account?
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
CI Config file
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'QUERY_STRING';
CI autoload file
$autoload['helper'] = array('url');
09-30-2011 Update:
In the .htaccess use:
# Options
Options -Multiviews
Options +FollowSymLinks
#Enable mod rewrite
RewriteEngine On
#the location of the root of your site
#if writing for subdirectories, you would enter /subdirectory
RewriteBase /
#Removes access to CodeIgniter 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]
#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|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
In the CI config file:
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
Source: codeigniter.com/wiki/Godaddy_Installaton_Tips
It's an .htaccess issue. Try changing your .htaccess file to:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]
Your updated .htaccess is right. you need a small change in it.
change below line in your .htaccess file:
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
and in your config.php
$config['uri_protocol'] = 'QUERY_STRING';
This is not a godaddy solution, but same error on my WAMP localhost...
I had a simple fix to this, which started to occur after I upgraded my WAMPserver. It had set up a new apache config and it had turned off the rewrite_module.
To fix, I just left click wamperver icon->Apache->Apache Modules->rewrite_module and make sure that is ticked.
I have a website on Joomla 1.5 in my base dir - http://example.com - and another project written in Kohana 2.x - http://example.com/app.
The problem is that .htaccess in the subdirectory isn't working properly.
Question: How and which one .htaccess to configure? In subdirectory, my .htaccess file looks like this:
RewriteEngine On
RewriteBase /app/
RewriteRule ^(application|system) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
The project in subdir always tries to go to the controller named "app" when I type "http://example.com/app".
I have added the following:
RewriteRule ^(.*)$ index.php/$1 [PT,L]
RewriteRule ^$ index.php/$1 [PT,L]
And it is working perfectly!
The problem was with the hosting server. It did not handle the PT correctly and required to add above lines.
Everything worked fine:
https://example.com/app/auth
https://example.com/app/controller_name/param
However, the following did not work:
https://example.com/app
Seems like the index.php hasn't been added when nothing else were passed. Hence the line:
RewriteRule ^$ index.php/$1 [PT,L]