Tutorial - Create news items. Getting 404 after submitting a new article - php

Getting to know Code Igniter, and was following this particular section of the tutorial:
http://codeigniter.com/user_guide/tutorial/create_news_items.html
Everything works until I click "Create news item". I receive 404 page and my URL bar looks like this:
http://localhost/tut/index.php/news/localhost/tut/index.php/news/create
Thinking maybe it's route's fault:
$route['default_controller'] = "news/index";
$route['404_override'] = '';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news'; // what's this for?
$route['news/create'] = 'news/create';
Also, my config.php:
$config['base_url'] = 'localhost/tut';
Any ideas?

According to this thead, you have your base_url set incorrectly. Please follow advice as per thread.

Related

Change the extension of a URI in CodeIgniter

I am making an API in PHP.
I want to add .json to the URL like this:
www.example.com/data.json
I am using CodeIgniter.
I have tried solving this in routes config file like this
$route['default_controller'] = 'data';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['/data.json'] = "/data/index";
You can add a url suffix in CodeIgniter by going to the config.php file and changing url_suffix:
$config['url_suffix'] = '.json';
This will make your website accesible via www.example.com/data and www.example.com/data.json
Check the documentation
If you want to enable it in some pages only you can use the routes like this:
$route['data.json'] = 'data/index';
If it's a page with dynamic path for example data/some-id.json use this:
$route['data/(:any).json'] = 'data/index/$1';

codeigniter using the name of controller in base url

I am working on a project in codeigniter. I have stuck in baseurl when I run the controller then it includes all the files of jquery and css. But when I run a function then the url of the jquery add the name of the controller.
This is my base url: $config['base_url'] = 'http://localhost/cod_login/';
I don't know why codeigniter is doing that.
Base URL is wrong. It should be like this
$config['base_url'] = 'http://localhost/cod_login/';
$config['base_url'] = 'http://localhost/poject_name'; # syntax
$config['base_url'] = 'http://stackoverflow.com/'; # example
In Routes
$route['default_controller'] = "defult_controler_name";
$route['404_override'] = '';
this is happen when you don't echo base URL only (echo) is missing thanks to all for ans

Codeigniter 404_override not working in routes

I try almost everything for fixed my problem but I can't
This is my routes file in codeigniter.
$route['default_controller'] = "main";
$route['404_override'] = 'my_error_page';
$route['(:any)'] = 'page/index/$1/';
My website working well normally but 404_override not redirect to my_error_page.
I see standart codeigniter 404 page like the picture
When I delete last line like following;
$route['default_controller'] = "main";
$route['404_override'] = 'my_error_page';
404_override redirect to my error page and of course web site not running well.
It is maybe a simple problem but I am confused.
Sorry bad english.
Please help.
Thaank you.

Duplicate content on multi language URL structure

I am using CodeIgnitore to develop a multi language website. At the moment I have set up the routing as follows.
$route['default_controller'] = "home";
$route['^(en|fr)/(.+)$'] = "$2";
$route['^(en|fr)$'] = $route['default_controller'];
$route['404_override'] = '';
Now I have the ability to access the homepage with the following URLs
domain.com
domain.com/en
Both these URLs shows the home page in english so will this be penalized for duplicate content & affect SEO. I have other URLs that would cause the same issue. Is there any solution this?
Thanks.
you can redirect domain.com -> domain.com/en.
So you don't have duplicate content.
In your home.php (application/controllers/home.php):
function __construct(){
parent::__construct();
if(!preg_match("/(en|fr)/",$_SERVER['HTTP_HOST'])){
$this->load->helper('url');
redirect('/en', 'location', 301);
}
}

CodeIgniter routing when routing url starts with variable

I am getting problem on codeigniter routing when routing url starts with variable like following -
$route['(:any)/(:any)'] = "home/index/0/N/DealsAmount/ASC/$1/$2";
i can to able to configure other routing url when i am passing values through url.
Example:
Following things work perfectly
$route['About-Us/Team'] = "aboutus/team";
$route['About-us/Jobs'] = "aboutus/jobs";
$route['About-Us/FAQ'] = "aboutus/faq";
But i use this url using varible like following --
$route['About-Us/Team/(:any)'] = "aboutus/team/$1";
$route['About-Us/Team/(:any)/(:any)'] = "aboutus/team/$1/$2";
$route['About-us/Jobs/(:any)'] = "aboutus/jobs/$1";
$route['About-Us/FAQ/(:num)'] = "aboutus/faq/$1";
then it redirects to the home page that means this routing is not working here $route['(:any)/(:any)'] is working how can i able to rout these types of url can you please advise me.
You have to put the routes with :any at the bottom. If you put it at the top other routes never get caught. This should be OK:
$route['About-Us/Team/(:any)/(:any)'] = "aboutus/team/$1/$2";
$route['About-Us/Team/(:any)'] = "aboutus/team/$1";
$route['About-us/Jobs/(:any)'] = "aboutus/jobs/$1";
$route['About-Us/FAQ/(:num)'] = "aboutus/faq/$1";
$route['(:any)/(:any)'] = "home/index/0/N/DealsAmount/ASC/$1/$2";

Categories