My CodeIgniter code in a subdirectory, so only index page is working when I hit any other request than it loading the parent folder index file.
Structure is:
Parent folder
index.php
sub folder / codeigniter set up
I have tried the htaccess code and request_uri in config.
I want to hit all my Codeigniter URL properly. Because on any request it loading the parent folder index.php file content.
Please set your .htaccess to this
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
And in the config use this
$base = "http://".$_SERVER['HTTP_HOST'];
$base .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $base;
$config['index_page'] = '';
Hopefully it will work :)
in the config file set your base url to the hosting site
$config['base_url'] = 'http://whateverthesitepathis';
then in the routes do this
$route['default_controller'] = 'folder/controller';
$route['(:any)'] = 'folder/controller/$1';
Related
I am new in Codeigniter framework. I am using HMVC design pattern
I have a issue with base url when I enter URL like this https://sitename/ its show blankpage and
when enter URL like this https://sitename/controller then show it main page of website
Config.php
$config['base_url'] = 'https://sitename/';
Routes.php
$route['default_controller'] = 'home';
$route['404_override'] = 'notify/show_404';
$route['translate_uri_dashes'] = FALSE;
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
ErrorDocument 404 index.php
Options -Indexes
How to show main page of website on this URL https://sitename/
I am using the Pagination library in Codeigniter, and the links it creates are exactly what I'm looking for. When I click on the link to go to the next page I get a 404.
My base url (index page) is: http://localhost/foo
My routing is:
$route['default_controller'] = 'main';
$route['page/(:num)'] = 'main/page/$1';
I want to be able to go to the url: http://localhost/foo/page/2 to get the second page. main is the controller. page is a function inside main.
I can type in the url http://localhost/foo/index.php/main/page/2 and get to the correct page, but I do not want to have the index.php/main in the url.
What am I doing wrong?
You aren't doing anything wrong. If you want to remove the index.php from the url:
Leave in blank $config['index_page'] attibute on the application/config/config.php file and make sure that you have a .htaccess that contains
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Also make sure the apache server has mod_rewrite enabled and in the configuration of apache AllowOverride attribute it's been set to All
In you Controller(In pagination code) $config['base_url'] should be
$config['base_url'] = base_url() . 'foo/page/';
In routes.php
$route['page/(:num)'] = 'main/page/$1';
$route['page'] = 'main/page';//add this line
In .htaccess,(Place outside application folder)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Note: To use base_url() in config/autoload.php
$autoload['helper'] = array('url');//url
and in config/config.php, (Change this)
$config['base_url'] = '';
$config['index_page'] = '';
I created a project using CI(version 3.0.0), and it works perfectly in XAMPP localhost. And i upload that project to sub domain then its giving an error Click here.
I Handle Router's and config setting as well. So what is this error?? how to avoid this?? There are some answers, But not suit for this.
Config.php
$config['base_url'] = '';
$config['index_page'] = '';
Routes.php
$route['default_controller'] = 'shop';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Change the name of your controller, model, and other your class to Capitalize.
Example :
your own controller test.php change to Test.php
It should be work.
Its because your server is Linux, and Linux is case sensitive.
I am using codeigniter version 3. It's working absolutely fine in localhost, but when I am trying to upload this to godaddy server ,only default controller is working. Please anyone suggest the necessary configuration changes. I tried changing the .htaccess file but not working.
Working configuration on my godaddy server.
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
routes.php
# Default
$route['default_controller'] = "home";
config.php
$config['base_url'] = '';
$config['index_page'] = '';
UPDATE:
1) base_url()
2) robots.txt
3) .htaccess
I am working in php project using codeigniter. I am very new to codeigniter. I have exiting project that i managed to run properly.But when i am inserting username and password,its
giving me error as=
"The requested URL /PRS/index.php/login was not found on this server."
I am using wamp server. httpd.conf file has documentRoot as "c:/wamp/www/PRS/"
My .htaccess file has code as-
RewriteEngine On
RewriteBase /PRS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /PRS/index.php/$1 [L]
My project's config.php file has code as-
$BASE_URL = "http://".$_SERVER['SERVER_NAME']."/PRS/" ;
$DB_HOST = "localhost";
$DB_USER = "root";
$DB_PASSWORD = "mysql";
$DB_NAME = "prsdb";
So can someone please help me..
At first make sure mod_rewrite is enabled in httpd.conf file and after that, overwrite your .htaccess file which is located your project root 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
And then set your base url like following..
$BASE_URL = "http://".$_SERVER['SERVER_NAME']."/PRS/";
And change your config file like following..
$config['index_page'] = '';
And finally use the following url to access..
prs.net/PRS/login
Or, you can check the following url to get some help..
Cannot remove index.php from CodeIgniter URL