webpage redirects to localhost - codeigniter

I am new to the world of web development. I have a website hosted. When I login it should take me to "member_dashboard.php". It redirects to this page on localhost. If I modify the localhost path, the remote redirect gets affected. I am using codeigniter as the framework. "base_url" is left blank. I tried setting the base url with the full http path of my index page still cannot fix it.
$config['base_url'] = '';

Do this changes as well
In config/routes.php
$route['default_controller'] = "";//default controller name
$route['404_override'] = '';
In config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
In config/autoload.php
$autoload['helper'] = array('url');
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>

The value on this key must be different on each environment. It file can not be included on control version. Considerate set it on .gitignore
$config['base_url'] = '';
//localhost environment
$config['base_url'] = 'http://localhost/';
//other env
$config['base_url'] = 'http://mypublicsite.com/';

Suppose your website name is example.com
So just keep
$config['base_url'] = 'http://example.com/';
under your application>config>config.php
Believe me your problem will solve because I personal did it and its working.
Have any questions or clarification, please let me know.
Thanks,
Amzad

Related

Running CodeIgniter Project locally on Windows

My CodeIgniter project is located in
C:/xampp/htdocs/Project/CodeIgniter/myproject
And I am using Xampp.
I set a base URL like this but it is not working.
$config['base_url'] = 'http://localhost:3000/myproject';
How I can run this project locally.
Quick debug time.
So what happens if you just use http://localhost in the url?
You should see whatever is in C:/xampp/htdocs/. So if you have a index.php in there, that should show up. If you don't have an index.php, then create one and see what happens.
Unless you have done "other things" in your setup, your Server Document Root will be C:/xampp/htdocs/. So it will be expecting your projects to be under that folder.
Now, you have decided to put your project under C:/xampp/htdocs/Project/CodeIgniter/myproject
So you would need to use http://localhost/Project/CodeIgniter/myproject
Do you get the Codeigniter welcome ( NOTE: if you haven't altered the default route)
A very quick fix, using your current settings, would be to relocate your project to
C:/xampp/htdocs/myproject as this is where the server is expecting to see it with the URL you are using.
What happens?
Personally, I never use localhost and create a virtual host which from memory XAMPP allows you to do from its management window. That way your project files can be located anywhere as long as the server knows where to find them. I will leave that as a project for you to look at.
How does your .htaccess file looks like?
It should look like this:
RewriteEngine on
RewriteBase /myproject
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
Replace
$config['base_url'] = 'http://localhost:3000/myproject';
To
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] = preg_replace('#/+$#','',dirname($_SERVER['SCRIPT_NAME'])).'/';
And your .htaccess file should look like this :
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|css|js|install|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
check your project path
and site base url
$config['base_url'] = 'http://localhost/your_project_path/';
if you have port
$config['base_url'] = 'http://localhost:3000/myproject';
in application/config/config.php
after that index.php is run
and set database connection if you want to conncet db
in your_project/application/config/database.php
db['default']['username'] ='your_db_root_user';
$db['default']['password'] = 'your_db_root_password';
$db['default']['database'] = 'database_name';
// The following values can probably stay the same.
$db['default']['hostname'] = 'localhost:3000';
$db['default']['dbdriver'] = "mysqli";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = true;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

Routing not working when codeigniter in sub folder

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';

codeigniter redirects all my pages to old domains except homepage

I have a up and running website (eg, abc.com) and i am trying to move the website to new server(eg, problem.com).
I have changed the base_url and also the database but .htaccess is the same.
After the transfer, my homepage is working fine but whenever i click on any page links from menu, its redirected to the page of the old website (for eg, abc.com/about) instead of problem.com/about. When i manually type the link in the browser as problem.com/about i see "No input file specified."
My .htaccess file is as follows:-
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
And my config.php file is as follows:-
$config['base_url'] = 'http://problem.com/';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['subclass_prefix'] = 'MY_';
$config['proxy_ips'] = '';
My old website is still online and working fine without any errors.

How to run website in live server? [duplicate]

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.

CodeIgniter - Rewriting url

There are many tutorials that talk about deleting index.php from the url. But I want one step forward of it.
The link is: www.example.com/index.php/controller/function/single-variable
I want it like: www.example.com/some-name-that-i-put/single-variable
I cannot find a tutorial to do such a thing. How to do it?
i wasnt sure whether you were wanting to do direct URL rewrites how CI does it out of the box or not... but this is how you do URL Rewrites:
your class/function/id example.com/news/article/13 transposes to: example.com/class/function/ID
http://codeigniter.com/user_guide/general/urls.html
you can set this by doing two things:
in your config.php file under application/config/ edit these:
approx line 80: $config['uri_protocol'] = 'REQUEST_URI'; // i set this to request_URI as it always works for me..
approx line 93: $config['url_suffix'] = '.html'; // this is optional, if you want /13.html
approx line 62: $config['index_page'] = ''; //set this to blank
create a .htaccess in http root:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
This is how you do URI Route changes
if you want to change the organization of the URI you can use URI Routes defined in routes.php as described here: http://codeigniter.com/user_guide/general/routing.html
Check out this CodeIgniter user guide.
Try this codeigniter user guide
https://www.codeigniter.com/user_guide/general/routing.html
Try this
in your config file place these
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['index_page'] = '';
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;
after this make a .htaccess file at your root directory and put this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
this will Definitely help you

Resources