When my website opens for the first time , it directly goes to this address: http://www.website.com/tr/main
But I want my link to be like this: http://www.website.com/
I can't remove "tr/main" links. How can I solve this problem?
Php Code:
$route['default_controller'] = "main";
$route['404_override'] = '';
$route['(tr|en)/(.+)$'] = '$2';
$route['(tr|en)$'] = $route['default_controller'];
Htaccess Code:
RewriteEngine On
# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/
RewriteBase /
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
In your config.php file write this code :-
$config['base_url']='http://Your Path/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['subclass_prefix'] = 'Base';
In your routes.php file write this code :-
$route['default_controller'] = "home";
$route['404_override'] = '';
Write the follwing code in your routes.php file :-
$route['default_controller'] = "main";
$route['404_override'] = '';
and then in your "main" controller i.e in main.php use
function index()
{
// write all your code inside this function
}
Related
Im trying to access my web application on others devices but when i click the login button it gives me a 404 error - the page doesnt exist.
On my computer works fine but in others i get that error.
I've check capital errors on the controllers names but it all seems to be fine.
Anyone have any idea on what it might be?
Config file:
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/CodeIgniter/mponto/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
htaccess file:
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]
Routes:
$route['default_controller'] = 'Pages';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['login'] = 'Utilizador/login';
maybe you should change
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/CodeIgniter/mponto/'
to
$config['base_url'] = 'http://#yourdomain.xxx/CodeIgniter/mponto/'
and you should use route default controller for your login not pages
i dont know it will work or not , i am newbie
Try this code
$config['is_https'] = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? true : false;
$config['base_url'] = 'http'.(($config['is_https']) ? 's' : '').'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['SCRIPT_NAME']).'/');
or
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/CodeIgniter/mponto/';
or
$config['base_url'] = 'http://Yourdomainname/CodeIgniter/mponto/';
You can just change base_url in config file.
$config['base_url']='http://base_url/path';
In localhost my site runs correctly, after i publish it in a test server it does not work and it prints this:
My login page runs without problems...
But after i click "login", i receive the error, but the URL is correct...
my config.php
$config['base_url'] = 'http://merge.***.it/merge/';
$config['index_page'] = 'index.php';
routes.php
$route['default_controller'] = 'auth/login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Try this.
Put blank in index_page.
$config['index_page'] = '';
& Use .htaccess in your root folder
RewriteEngine on
RewriteCond $1 !^(index\.php|phpinfo\.php|Charts|assets|uploads|application|sitemap\.xml|robots\.txt|gyan\.rss)
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
if i´m on a category/index/$1 Site of my Page and want to call back to domain.com/home, it doesn't work for me.
Thats my routes
$route['default_controller'] = 'home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['admin'] = 'admin/login';
$route['category/(:any)'] = 'category/index/$1';
$route['category/(:any)/(:num)'] = 'category/index/$1/$2';
$route['page/(:any)'] = 'page/index/$1';
If i call domain.com/about and click on my navigation "home", its working. but if i make domain.com/aboutdetails/index/1 he make on home click this one:
domain.com/aboutdetails/index/home
htaccess
#RewriteEngine on
#RewriteCond $1 !^(index\.php|images|robots\.txt|style|cdn|check\.php)
RewriteEngine on
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I think, you can use :
Home
If you want go to home with your configuration router using domain.com.
If you want use domain.com/home you add next line route:
$route['home'] = 'home/index';
Considerer use initial en and limiter( regex ), example:
$route['^home$'] = 'home/index';
Good, To print link don't use base_url(), it is use to load assets or other an return project root, Use site_url().
In the application/config.php set empty to $config['index_page']:
//$config['index_page'] = 'index.php';
$config['index_page'] = '';
And then create link with site_url():
site_url( 'home' );
If you want create link with more params you maybe pass array.
site_url( array( 'home', $param2 ) );
I'm using codeigniter on my wamp and everything is fine but when I upload it on live server the default_controller is working but the other controller are 404 not found or "The requested URL /Sample_controller was not found on this server".
Here is my sample controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sample_controller extends CI_Controller {
function __construct(){
parent::__construct();
}
public function index(){
print_r('Hello World');
}
}
and here's my config.php:
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
$config['allow_get_array'] = TRUE;
and this is my router.php:
$route['default_controller'] = 'login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
and my .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !www.sampleurl.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteCond $1 !^(index\.php|assets|user_assets|tmp|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
if I tried this sampleurl.com it's working fine and will direct me to my default controller which is the login but if i tried this sampleurl.com/sample_controller or sampleurl.com/login it will lead me to 404 not found The requested URL /sample_controller was not found on this server. Apache/2.4.7 (Ubuntu) Server at sampleurl.com Port 80
I hope someone can help me on this
I tried changing them to:
$config['uri_protocol'] = AUTO
$config['enable_query_strings'] = TRUE;
and it's still not working.
You need to add a route for that controller to work
$route['sample_controller'] = 'sample_controller';
For every new controller you create you need to have a route for it
According to your code, you may have these 2 issues:
1- As per documentation you are required to make your controller filename first character Uppercase.
2- Try adding a question mark "?" in your .htaccess file's last rule. Also remove the "/" before "index.php" check the code below.
Current code:
RewriteRule ^(.*)$ /index.php/$1 [L]
New code:
RewriteRule ^(.*)$ index.php?/$1 [L]
Just simply change
RewriteBase /folder
This line of code in your .htaccess file to appropriate folder name of your project and it will work fine.
The app which i'm creating using codeigniter is loading on my localhost. But when i uploaded the same into cpanel its showing "404 Page Not Found".
I'm able to access default welcome controller other than this it shows 404 page not found.
Below are my configuration in application/config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
.htaccess configurations are as follows
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
configuration in application/config/routes.php are as below
$route['default_controller'] = 'login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
If I change the default_controller to welcome then welcome is loading fine.
--Thanks in advance
As said in the comments : Your controller's file name must start with an uppercase.
See http://codeigniter.com/userguide3/changelog.html
Changed filenaming convention (class file names now must be Ucfirst
and everything else in lowercase).
:-)